This library is created by implementing gocache and require redis v8.
go get -d github.com/morkid/gocache-redis/v8
Available versions:
- github.com/morkid/gocache-redis/v9 (on progress)
- github.com/morkid/gocache-redis/v8 for redis client v8
- github.com/morkid/gocache-redis/v7 for redis client v7
- github.com/morkid/gocache-redis/v5 for redis client v5
- github.com/morkid/gocache-redis/v4 for redis client v4
- github.com/morkid/gocache-redis/v3 for redis client v3
package main
import (
"time"
"fmt"
cache "github.com/morkid/gocache-redis/v8"
"github.com/go-redis/redis/v8"
)
func main() {
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
})
config := cache.RedisCacheConfig{
Client: client,
ExpiresIn: 10 * time.Second,
}
adapter := *cache.NewRedisCache(config)
adapter.Set("foo", "bar")
if adapter.IsValid("foo") {
value, err := adapter.Get("foo")
if nil != err {
fmt.Println(err)
} else if value != "bar" {
fmt.Println("value not equals to bar")
} else {
fmt.Println(value)
}
adapter.Clear("foo")
if adapter.IsValid("foo") {
fmt.Println("Failed to remove key foo")
}
}
}
Published under the MIT License.