Documentation
¶
Overview ¶
Package redis provides a Redis-backed persistent feature store for the LaunchDarkly Go SDK.
For more details about how and why you can use a persistent feature store, see: https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store
To use the Redis feature store with the LaunchDarkly client:
factory, err := redis.NewRedisFeatureStoreFactory() if err != nil { ... } config := ld.DefaultConfig config.FeatureStoreFactory = factory client, err := ld.MakeCustomClient("sdk-key", config, 5*time.Second)
The default Redis pool configuration uses an address of localhost:6379, a maximum of 16 concurrent connections, and blocking connection requests. You may also customize other properties of the feature store by providing options to NewRedisFeatureStoreFactory, for example:
factory, err := redis.NewRedisFeatureStoreFactory(redis.URL(myRedisURL), redis.CacheTTL(30*time.Second))
For advanced customization of the underlying Redigo client, use the DialOptions or Pool options with NewRedisFeatureStoreFactory. Note that some Redis client features can also be specified as part of the URL: Redigo supports the redis:// syntax (https://www.iana.org/assignments/uri-schemes/prov/redis), which can include a password and a database number, as well as rediss:// (https://www.iana.org/assignments/uri-schemes/prov/rediss), which enables TLS.
If you are also using Redis for other purposes, the feature store can coexist with other data as long as you are not using the same keys. By default, the keys used by the feature store will always start with "launchdarkly:"; you can change this to another prefix if desired.
Index ¶
- Constants
- func NewRedisFeatureStoreFactory(options ...FeatureStoreOption) (ld.FeatureStoreFactory, error)
- func NewRedisFeatureStoreWithDefaults(options ...FeatureStoreOption) (ld.FeatureStore, error)deprecated
- type FeatureStoreOption
- func CacheTTL(ttl time.Duration) FeatureStoreOption
- func DialOptions(options ...r.DialOption) FeatureStoreOption
- func HostAndPort(host string, port int) FeatureStoreOption
- func Logger(logger ld.Logger) FeatureStoreOption
- func Pool(pool *r.Pool) FeatureStoreOption
- func Prefix(prefix string) FeatureStoreOption
- func URL(url string) FeatureStoreOption
- type RedisFeatureStore
- func NewRedisFeatureStore(host string, port int, prefix string, timeout time.Duration, logger ld.Logger) *RedisFeatureStoredeprecated
- func NewRedisFeatureStoreFromUrl(url, prefix string, timeout time.Duration, logger ld.Logger) *RedisFeatureStoredeprecated
- func NewRedisFeatureStoreWithPool(pool *r.Pool, prefix string, timeout time.Duration, logger ld.Logger) *RedisFeatureStoredeprecated
- func (store *RedisFeatureStore) All(kind ld.VersionedDataKind) (map[string]ld.VersionedData, error)
- func (store *RedisFeatureStore) Delete(kind ld.VersionedDataKind, key string, version int) error
- func (store *RedisFeatureStore) Get(kind ld.VersionedDataKind, key string) (ld.VersionedData, error)
- func (store *RedisFeatureStore) Init(allData map[ld.VersionedDataKind]map[string]ld.VersionedData) error
- func (store *RedisFeatureStore) Initialized() bool
- func (store *RedisFeatureStore) Upsert(kind ld.VersionedDataKind, item ld.VersionedData) error
Constants ¶
const ( // DefaultURL is the default URL for connecting to Redis, if you use // NewRedisFeatureStoreWithDefaults. You can specify otherwise with the RedisURL option. // If you are using the other constructors, you must specify the URL explicitly. DefaultURL = "redis://localhost:6379" // DefaultPrefix is a string that is prepended (along with a colon) to all Redis keys used // by the feature store. You can change this value with the Prefix() option for // NewRedisFeatureStoreWithDefaults, or with the "prefix" parameter to the other constructors. DefaultPrefix = "launchdarkly" // DefaultCacheTTL is the default amount of time that recently read or updated items will // be cached in memory, if you use NewRedisFeatureStoreWithDefaults. You can specify otherwise // with the CacheTTL option. If you are using the other constructors, their "timeout" // parameter serves the same purpose and there is no default. DefaultCacheTTL = 15 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func NewRedisFeatureStoreFactory ¶
func NewRedisFeatureStoreFactory(options ...FeatureStoreOption) (ld.FeatureStoreFactory, error)
NewRedisFeatureStoreFactory returns a factory function for a Redis-backed feature store.
By default, it uses DefaultURL as the Redis address, DefaultPrefix as the prefix for all keys, DefaultCacheTTL as the duration for in-memory caching, no authentication and a default connection pool configuration (see package description for details). You may override any of these with FeatureStoreOption values created with RedisURL, RedisHostAndPort, RedisPool, Prefix, CacheTTL, Logger, or Auth.
Set the FeatureStoreFactory field in your Config to the returned value. Because this is specified as a factory function, the Redis client is not actually created until you create the SDK client. This also allows it to use the same logging configuration as the SDK, so you do not have to specify the Logger option separately.
func NewRedisFeatureStoreWithDefaults
deprecated
func NewRedisFeatureStoreWithDefaults(options ...FeatureStoreOption) (ld.FeatureStore, error)
NewRedisFeatureStoreWithDefaults constructs a new Redis-backed feature store.
By default, it uses DefaultURL as the Redis address, DefaultPrefix as the prefix for all keys, DefaultCacheTTL as the duration for in-memory caching, no authentication and a default connection pool configuration (see package description for details). You may override any of these with FeatureStoreOption values created with RedisURL, RedisHostAndPort, RedisPool, Prefix, CacheTTL, Logger, or Auth.
Deprecated: Use NewRedisFeatureStoreFactory instead
Types ¶
type FeatureStoreOption ¶
type FeatureStoreOption interface {
// contains filtered or unexported methods
}
FeatureStoreOption is the interface for optional configuration parameters that can be passed to NewRedisFeatureStoreFactory. These include UseConfig, Prefix, CacheTTL, and UseLogger.
func CacheTTL ¶
func CacheTTL(ttl time.Duration) FeatureStoreOption
CacheTTL creates an option for NewRedisFeatureStoreFactory to set the amount of time that recently read or updated items should remain in an in-memory cache. This reduces the amount of database access if the same feature flags are being evaluated repeatedly.
The default value is DefaultCacheTTL. A value of zero disables in-memory caching completely. A negative value means data is cached forever (i.e. it will only be read again from the database if the SDK is restarted). Use the "cached forever" mode with caution: it means that in a scenario where multiple processes are sharing the database, and the current process loses connectivity to LaunchDarkly while other processes are still receiving updates and writing them to the database, the current process will have stale data.
factory, err := redis.NewRedisFeatureStoreFactory(redis.CacheTTL(30*time.Second))
func DialOptions ¶
func DialOptions(options ...r.DialOption) FeatureStoreOption
DialOptions creates an option for NewRedisFeatureStoreFactory to specify any of the advanced Redis connection options supported by Redigo, such as DialPassword.
import ( redigo "github.com/garyburd/redigo/redis" "gopkg.in/launchdarkly/go-server-sdk.v4/redis" ) factory, err := redis.NewRedisFeatureStoreFactory(redis.DialOption(redigo.DialPassword("verysecure123")))
Note that some Redis client features can also be specified as part of the URL: see comments on the URL() option.
func HostAndPort ¶
func HostAndPort(host string, port int) FeatureStoreOption
HostAndPort creates an option for NewRedisFeatureStoreWithDefaults to specify the Redis host address as a hostname and port.
factory, err := redis.NewRedisFeatureStoreFactory(redis.HostAndPort("my-redis-host", 6379))
func Logger ¶
func Logger(logger ld.Logger) FeatureStoreOption
Logger creates an option for NewRedisFeatureStore, to specify where to send log output.
If you use NewConsulFeatureStoreFactory rather than the deprecated constructors, you do not need to specify a logger because it will use the same logging configuration as the SDK client.
store, err := redis.NewRedisFeatureStore(redis.Logger(myLogger))
func Pool ¶
func Pool(pool *r.Pool) FeatureStoreOption
Pool creates an option for NewRedisFeatureStoreFactory to make the feature store use a specific connection pool configuration. If not specified, it will create a default configuration (see package description). Specifying this option will cause any address specified with RedisURL or RedisHostAndPort to be ignored.
factory, err := redis.NewRedisFeatureStoreFactory(redis.Pool(myPool))
If you only need to change basic connection options such as providing a password, it is simpler to use DialOptions.
func Prefix ¶
func Prefix(prefix string) FeatureStoreOption
Prefix creates an option for NewRedisFeatureStoreFactory to specify a string that should be prepended to all Redis keys used by the feature store. A colon will be added to this automatically. If this is unspecified or empty, DefaultPrefix will be used.
factory, err := redis.NewRedisFeatureStoreFactory(redis.Prefix("ld-data"))
func URL ¶
func URL(url string) FeatureStoreOption
URL creates an option for NewRedisFeatureStoreFactory to specify the Redis host URL. If not specified, the default value is DefaultURL.
factory, err := redis.NewRedisFeatureStoreFactory(redis.URL("redis://my-redis-host:6379"))
Note that some Redis client features can also be specified as part of the URL: Redigo supports the redis:// syntax (https://www.iana.org/assignments/uri-schemes/prov/redis), which can include a password and a database number, as well as rediss:// (https://www.iana.org/assignments/uri-schemes/prov/rediss), which enables TLS.
type RedisFeatureStore ¶
type RedisFeatureStore struct {
// contains filtered or unexported fields
}
RedisFeatureStore is a Redis-backed feature store implementation.
func NewRedisFeatureStore
deprecated
func NewRedisFeatureStore(host string, port int, prefix string, timeout time.Duration, logger ld.Logger) *RedisFeatureStore
NewRedisFeatureStore constructs a new Redis-backed feature store connecting to the specified host and port. It uses a default connection pool configuration (see package description for details). The "prefix", "timeout", and "logger" parameters are equivalent to the Prefix, CacheTTL, and Logger options for NewRedisFeatureStoreWithDefaults.
Deprecated: It is simpler to use NewRedisFeatureStoreFactory(redis.HostAndPort(host, port)) and override any other defaults as needed.
func NewRedisFeatureStoreFromUrl
deprecated
func NewRedisFeatureStoreFromUrl(url, prefix string, timeout time.Duration, logger ld.Logger) *RedisFeatureStore
NewRedisFeatureStoreFromUrl constructs a new Redis-backed feature store connecting to the specified URL. It uses a default connection pool configuration (see package description for details). The "prefix", "timeout", and "logger" parameters are equivalent to the Prefix, CacheTTL, and Logger options for NewRedisFeatureStoreWithDefaults.
Deprecated: It is simpler to use NewRedisFeatureStoreFactory(redis.URL(url)) and override any other defaults as needed.
func NewRedisFeatureStoreWithPool
deprecated
func NewRedisFeatureStoreWithPool(pool *r.Pool, prefix string, timeout time.Duration, logger ld.Logger) *RedisFeatureStore
NewRedisFeatureStoreWithPool constructs a new Redis-backed feature store with the specified redigo pool configuration. The "prefix", "timeout", and "logger" parameters are equivalent to the Prefix, CacheTTL, and Logger options for NewRedisFeatureStoreWithDefaults.
Deprecated: It is simpler to use NewRedisFeatureStoreFactory(redis.Pool(pool)) and override any other defaults as needed.
func (*RedisFeatureStore) All ¶
func (store *RedisFeatureStore) All(kind ld.VersionedDataKind) (map[string]ld.VersionedData, error)
All returns all the objects of a given kind from the store
func (*RedisFeatureStore) Delete ¶
func (store *RedisFeatureStore) Delete(kind ld.VersionedDataKind, key string, version int) error
Delete removes an item of a given kind from the store
func (*RedisFeatureStore) Get ¶
func (store *RedisFeatureStore) Get(kind ld.VersionedDataKind, key string) (ld.VersionedData, error)
Get returns an individual object of a given type from the store
func (*RedisFeatureStore) Init ¶
func (store *RedisFeatureStore) Init(allData map[ld.VersionedDataKind]map[string]ld.VersionedData) error
Init populates the store with a complete set of versioned data
func (*RedisFeatureStore) Initialized ¶
func (store *RedisFeatureStore) Initialized() bool
Initialized returns whether redis contains an entry for this environment
func (*RedisFeatureStore) Upsert ¶
func (store *RedisFeatureStore) Upsert(kind ld.VersionedDataKind, item ld.VersionedData) error
Upsert inserts or replaces an item in the store unless there it already contains an item with an equal or larger version