LaunchDarkly Server-side SDK for Go - Redis integration

Circle CI Documentation

This library provides a Redis-backed persistence mechanism (data store) for the LaunchDarkly Go SDK, replacing the default in-memory data store. The Redis API implementation it uses is Redigo.

This version of the library requires at least version 5.0.0 of the LaunchDarkly Go SDK. In earlier Go SDK versions, the ldredis package was built into the SDK (

The minimum Go version is 1.13.

For more information, see also: Using a persistent feature store.

Quick setup

This assumes that you have already installed the LaunchDarkly Go SDK.

  1. Import the LaunchDarkly SDK packages and the package for this library:
import (
    ld ""
    ldredis ""
  1. When configuring your SDK client, add the Redis data store as a PersistentDataStore. You may specify any custom Redis options using the methods of RedisDataStoreBuilder. For instance, to customize the Redis URL:
    var config ld.Config{}
    config.DataStore = ldcomponents.PersistentDataStore(

By default, the store will try to connect to a local Redis instance on port 6379.

Caching behavior

The LaunchDarkly SDK has a standard caching mechanism for any persistent data store, to reduce database traffic. This is configured through the SDK's PersistentDataStoreBuilder class as described the SDK documentation. For instance, to specify a cache TTL of 5 minutes:

    var config ld.Config{}
    config.DataStore = ldcomponents.PersistentDataStore(

LaunchDarkly overview

LaunchDarkly is a feature management platform that serves over 100 billion feature flags daily to help teams build better software, faster. Get started using LaunchDarkly today!

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out our documentation for a complete list.
  • Explore LaunchDarkly
Expand ▾ Collapse ▴



Package ldredis provides a Redis-backed persistent data store for the LaunchDarkly Go SDK.

For more details about how and why you can use a persistent data store, see:

To use the Redis data store with the LaunchDarkly client:

import ldredis ""

config := ld.Config{
    DataStore: ldcomponents.PersistentDataStore(ldredis.DataStore()),
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 customize the configuration by using the methods of the ldredis.DataStoreBuilder returned by ldredis.DataStore():

config := ld.Config{
    DataStore: ldcomponents.PersistentDataStore(

Note that CacheSeconds() is not a method of ldredis.DataStoreBuilder, but rather a method of ldcomponents.PersistentDataStore(), because the caching behavior is provided by the SDK for all database integrations.

For advanced customization of the underlying Redigo client, use the DialOptions or Pool options with ldredis.DataStore(). Note that some Redis client features can also be specified as part of the URL: Redigo supports the redis:// syntax (, which can include a password and a database number, as well as rediss:// (, which enables TLS.

If you are also using Redis for other purposes, the data store can coexist with other data as long as you are not using the same keys. By default, the keys used by the data store will always start with "launchdarkly:"; you can change this to another prefix if desired.



const (
	// DefaultURL is the default URL for connecting to Redis, if you use
	// NewRedisDataStoreWithDefaults. 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 data store. You can change this value with the Prefix() option for
	// NewRedisDataStoreWithDefaults, or with the "prefix" parameter to the other constructors.
	DefaultPrefix = "launchdarkly"


This section is empty.


This section is empty.


type DataStoreBuilder

type DataStoreBuilder struct {
	// contains filtered or unexported fields

DataStoreBuilder is a builder for configuring the Redis-based persistent data store.

Obtain an instance of this type by calling DataStore(). After calling its methods to specify any desired custom settings, wrap it in a PersistentDataStoreBuilder by calling ldcomponents.PersistentDataStore(), and then store this in the SDK configuration's DataStore field.

Builder calls can be chained, for example:

config.DataStore = ldredis.DataStore().URL("redis://hostname").Prefix("prefix")

You do not need to call the builder's CreatePersistentDataStore() method yourself to build the actual data store; that will be done by the SDK.

func DataStore

func DataStore() *DataStoreBuilder

DataStore returns a configurable builder for a Redis-backed data store.

func (*DataStoreBuilder) CreatePersistentDataStore

func (b *DataStoreBuilder) CreatePersistentDataStore(
	context interfaces.ClientContext,
) (interfaces.PersistentDataStore, error)

CreatePersistentDataStore is called internally by the SDK to create the data store implementation object.

func (*DataStoreBuilder) DescribeConfiguration

func (b *DataStoreBuilder) DescribeConfiguration() ldvalue.Value

DescribeConfiguration is used internally by the SDK to inspect the configuration.

func (*DataStoreBuilder) DialOptions

func (b *DataStoreBuilder) DialOptions(options ...r.DialOption) *DataStoreBuilder

DialOptions specifies any of the advanced Redis connection options supported by Redigo, such as DialPassword.

import (
    redigo ""
    ldredis ""
config.DataSource = ldcomponents.PersistentDataStore(

Note that some Redis client features can also be specified as part of the URL: see URL().

func (*DataStoreBuilder) HostAndPort

func (b *DataStoreBuilder) HostAndPort(host string, port int) *DataStoreBuilder

HostAndPort is a shortcut for specifying the Redis host address as a hostname and port.

func (*DataStoreBuilder) Pool

func (b *DataStoreBuilder) Pool(pool *r.Pool) *DataStoreBuilder

Pool specifies that the data store should 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 URL() or HostAndPort() to be ignored.

If you only need to change basic connection options such as providing a password, it is simpler to use DialOptions().

func (*DataStoreBuilder) Prefix

func (b *DataStoreBuilder) Prefix(prefix string) *DataStoreBuilder

Prefix specifies a string that should be prepended to all Redis keys used by the data store. A colon will be added to this automatically. If this is unspecified or empty, DefaultPrefix will be used.

func (*DataStoreBuilder) URL

func (b *DataStoreBuilder) URL(url string) *DataStoreBuilder

URL specifies the Redis host URL. If not specified, the default value is DefaultURL.

Note that some Redis client features can also be specified as part of the URL: Redigo supports the redis:// syntax (, which can include a password and a database number, as well as rediss:// (, which enables TLS.