redis

package
v4.0.0-...-0933bec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

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:

store, err := redis.NewRedisFeatureStoreWithDefaults()
if err != nil { ... }

config := ld.DefaultConfig
config.FeatureStore = store
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. To customize any properties of the connection pool, use the Pool option or the NewRedisFeatureStoreWithPool constructor. You may also customize other properties of the feature store by providing options to NewRedisFeatureStoreWithDefaults, for example:

store, err := redis.NewRedisFeatureStoreWithDefaults(redis.URL(myRedisURL),
    redis.CacheTTL(30*time.Second))

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

View Source
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 NewRedisFeatureStoreWithDefaults

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, 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, or Logger.

Types

type FeatureStoreOption

type FeatureStoreOption interface {
	// contains filtered or unexported methods
}

FeatureStoreOption is the interface for optional configuration parameters that can be passed to NewRedisFeatureStoreWithDefaults. These include UseConfig, Prefix, CacheTTL, and UseLogger.

func CacheTTL

func CacheTTL(ttl time.Duration) FeatureStoreOption

CacheTTL creates an option for NewRedisFeatureStoreWithDefaults 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.

store, err := redis.NewRedisFeatureStoreWithDefaults(redis.CacheTTL(30*time.Second))

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.

store, err := redis.NewRedisFeatureStoreWithDefaults(redis.HostAndPort("my-redis-host", 6379))

func Logger

func Logger(logger ld.Logger) FeatureStoreOption

Logger creates an option for NewDynamoDBFeatureStore, to specify where to send log output. If not specified, a log.Logger is used.

store, err := redis.NewRedisFeatureStoreWithDefaults(redis.Logger(myLogger))

func Pool

func Pool(pool *r.Pool) FeatureStoreOption

Pool creates an option for NewRedisFeatureStoreWithDefaults 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.

store, err := redis.NewRedisFeatureStoreWithDefaults(redis.Pool(myPool))

func Prefix

func Prefix(prefix string) FeatureStoreOption

Prefix creates an option for NewRedisFeatureStoreWithDefaults 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.

store, err := redis.NewRedisFeatureStoreWithDefaults(redis.Prefix("ld-data"))

func URL

func URL(url string) FeatureStoreOption

URL creates an option for NewRedisFeatureStoreWithDefaults to specify the Redis host URL. If not specified, the default value is DefaultURL.

store, err := redis.NewRedisFeatureStoreWithDefaults(redis.URL("redis://my-redis-host:6379"))

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 NewRedisFeatureStoreWithDefaults(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 NewRedisFeatureStoreWithDefaults(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 NewRedisFeatureStoreWithDefaults(redis.Pool(pool)) and override any other defaults as needed.

func (*RedisFeatureStore) All

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL