go-server-sdk.v4: gopkg.in/launchdarkly/go-server-sdk.v4/redis Index | Files

package redis

import "gopkg.in/launchdarkly/go-server-sdk.v4/redis"

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

Package Files

redis.go

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
)

func NewRedisFeatureStoreFactory Uses

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 Uses

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

type FeatureStoreOption Uses

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 Uses

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. If it is zero, there will be no in-memory caching. The default value is DefaultCacheTTL.

factory, err := redis.NewRedisFeatureStoreFactory(redis.CacheTTL(30*time.Second))

func DialOptions Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

type RedisFeatureStore struct {
    // contains filtered or unexported fields
}

RedisFeatureStore is a Redis-backed feature store implementation.

func NewRedisFeatureStore Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (store *RedisFeatureStore) Initialized() bool

Initialized returns whether redis contains an entry for this environment

func (*RedisFeatureStore) Upsert Uses

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

Package redis imports 7 packages (graph) and is imported by 2 packages. Updated 2019-09-15. Refresh now. Tools for package owners.