Documentation
¶
Overview ¶
Package redis provides a Redis Client implementation of the driver.Cache interface. It uses the go-redis library to interact with a Redis Client.
URL Format: ¶
The URL should have the following format:
redis://<host>:<port>[?query]
The <host>:<port> pair corresponds to the Redis Client node.
The optional query part can be used to configure the Redis Client options through query parameters. The keys of the query parameters should match the case-insensitive field names of the Options structure (excluding redis.Options.Addr).
Usage ¶
import ( "context" "log" cache "github.com/bartventer/gocache" _ "github.com/bartventer/gocache/redis" ) func main() { ctx := context.Background() urlStr := "redis://localhost:7000?maxretries=5&minretrybackoff=1000ms" c, err := cache.OpenCache(ctx, urlStr) if err != nil { log.Fatalf("Failed to initialize cache: %v", err) } // ... use c with the cache.Cache interface }
You can create a Redis cache with New:
import ( "context" "github.com/bartventer/gocache/redis" ) func main() { ctx := context.Background() c := redis.New[string](ctx, &redis.Options{ RedisOptions: redis.RedisOptions{ Addr: "localhost:6379", MaxRetries: 5, MinRetryBackoff: 1000 * time.Millisecond, }, }) // ... use c with the cache.Cache interface }
Index ¶
Constants ¶
const (
// DefaultCountLimit is the default value for the [Config.CountLimit] option.
DefaultCountLimit = 10
)
const Scheme = "redis"
Scheme is the cache scheme for Redis.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶ added in v0.8.0
type Config struct { // CountLimit is the hint to the SCAN command about the amount of work to be done at each call. // The default value is 10. // // Refer to [redis scan] for more information. // // [redis scan]: https://redis.io/docs/latest/commands/scan/ CountLimit int64 }
Config is a configuration for [gocache] to customize the Redis cache.
type Options ¶ added in v0.8.0
type Options struct { *Config RedisOptions }
Options is the configuration for the Redis cache.
type RedisOptions ¶ added in v0.8.0
type RedisOptions = redis.Options
RedisOptions is an alias for the redis.Options type.