Documentation
¶
Overview ¶
Package rediscluster provides a Redis Cluster implementation of the driver.Cache interface. It uses the go-redis library to interact with a Redis Cluster.
URL Format: ¶
The URL should have the following format:
rediscluster://<host1>:<port1>,<host2>:<port2>,...,<hostN>:<portN>[?query]
Each <host>:<port> pair corresponds to a Redis Cluster node. You can specify any number of nodes, each separated by a comma.
The optional query part can be used to configure the Redis Cluster options through query parameters. The keys of the query parameters should match the case-insensitive field names of the Options structure (excluding redis.ClusterOptions.Addrs).
Usage ¶
import (
"context"
"log"
"net/url"
"github.com/bartventer/gocache"
_ "github.com/bartventer/gocache/rediscluster"
)
func main() {
ctx := context.Background()
urlStr := "rediscluster://localhost:7000,localhost:7001,localhost:7002?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 Cluster cache with New:
import (
"context"
"log"
"net/url"
"github.com/bartventer/gocache/rediscluster"
)
func main() {
ctx := context.Background()
c := rediscluster.New[string](ctx, &rediscluster.Options{
ClusterOptions: rediscluster.ClusterOptions{
Addrs: []string{"localhost:7000", "localhost:7001", "localhost:7002"},
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 = "rediscluster"
Scheme is the cache scheme for Redis Cluster.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClusterOptions ¶ added in v0.8.0
type ClusterOptions = redis.ClusterOptions
ClusterOptions is an alias for the redis.ClusterOptions type.
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 cluster cache.
type Options ¶ added in v0.8.0
type Options struct {
*Config
ClusterOptions
}
Options is the configuration for the Redis cluster cache.