Documentation
¶
Overview ¶
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: https://docs.launchdarkly.com/sdk/concepts/data-stores
To use the Redis data store with the LaunchDarkly client:
import ldredis "github.com/launchdarkly/go-server-sdk-redis-go-redis" config := ld.Config{ DataStore: ldcomponents.PersistentDataStore(ldredis.DataStore()), } client, err := ld.MakeCustomClient("sdk-key", config, 5*time.Second)
The default configuration uses an address of localhost:6379. You may customize the configuration by using the methods of the ldredis.DataStoreBuilder returned by ldredis.DataStore():
config := ld.Config{ DataStore: ldcomponents.PersistentDataStore( ldredis.DataStore().URL(myRedisURL), ).CacheSeconds(30), }
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 go-redis client, use the Options method with ldredis.DataStore(). Note that some Redis client features can also be specified as part of the URL.
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 using the ldredis.DataStoreBuilder's Prefix method.
Index ¶
- Constants
- type DataStoreBuilder
- func (b *DataStoreBuilder) Addresses(addresses ...string) *DataStoreBuilder
- func (b *DataStoreBuilder) Build(context subsystems.ClientContext) (subsystems.PersistentDataStore, error)
- func (b *DataStoreBuilder) CheckOnStartup(value bool) *DataStoreBuilder
- func (b *DataStoreBuilder) DescribeConfiguration() ldvalue.Value
- func (b *DataStoreBuilder) HostAndPort(host string, port int) *DataStoreBuilder
- func (b *DataStoreBuilder) Master(masterName string) *DataStoreBuilder
- func (b *DataStoreBuilder) Options(options redis.UniversalOptions) *DataStoreBuilder
- func (b *DataStoreBuilder) Prefix(prefix string) *DataStoreBuilder
- func (b *DataStoreBuilder) URL(url string) *DataStoreBuilder
Constants ¶
const ( // 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. // // See also DefaultClusterPrefix. DefaultPrefix = "launchdarkly" // DefaultClusterPrefix is an additional string of "{ld}." that is added before the // configured prefix (or DefaultPrefix) if you are connecting to a Redis cluster, if the // prefix does not already include curly braces. // // For instance, if you set the prefix to "app1", and you are using a single Redis node, // all keys will start with "app1:", but if you are using a cluster, they will start with // "{ld}.app1:". But if you set the prefix to "{xyz}app1", then the keys will start with // "{xyz}app1:" regardless of whether you are using a cluster or not. // // The reason for this is that in a Redis cluster, keys that begin with the same string in // curly braces are grouped together into one hash slot in the cluster. That allows // operations on those keys to be atomic, which the LaunchDarkly SDK Redis integration // relies on. // // When using a single Redis node rather than a cluster, there is no special meaning for // braces-- they are treated like any other characters in keys. DefaultClusterPrefix = "{ld}." )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 Build() 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) Addresses ¶
func (b *DataStoreBuilder) Addresses(addresses ...string) *DataStoreBuilder
Addresses specifies Redis host addresses. This is a shortcut for setting the Addrs field with Options.
If multiple addresses are given, and a Master has been set, this is treated as a list of Redis Sentinel nodes.
If multiple addresses are given, and no Master has been set, it is treated as a list of cluster nodes.
If no addresses are given, the default address of localhost:6379 will be used.
Calling Addresses overwrites any addresses previously set with HostAndPort or Options.
func (*DataStoreBuilder) Build ¶
func (b *DataStoreBuilder) Build( context subsystems.ClientContext, ) (subsystems.PersistentDataStore, error)
Build is called internally by the SDK to create the data store implementation object.
func (*DataStoreBuilder) CheckOnStartup ¶
func (b *DataStoreBuilder) CheckOnStartup(value bool) *DataStoreBuilder
CheckOnStartup sets whether the data store should check the availability of the Redis server when the SDK is initialized. If so, the SDK will refuse to start unless the server is available. This is true by default.
func (*DataStoreBuilder) DescribeConfiguration ¶
func (b *DataStoreBuilder) DescribeConfiguration() ldvalue.Value
DescribeConfiguration is used internally by the SDK to inspect the configuration.
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.
To use multiple Redis hosts in cluster mode, use Addresses; or, use Options and set the Addrs field.
Calling HostAndPort overwrites any addresses previously set with Addresses or Options.
func (*DataStoreBuilder) Master ¶
func (b *DataStoreBuilder) Master(masterName string) *DataStoreBuilder
Master sets the master hostname, when using Redis Sentinel.
func (*DataStoreBuilder) Options ¶
func (b *DataStoreBuilder) Options(options redis.UniversalOptions) *DataStoreBuilder
Options sets all the parameters supported by the go-redis UniversalOptions type.
This overwrites any previous setting of HostAndPort or Addresses.
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 be specified either as part of the URL or with Options. For instance, the Password and DB fields in Options can be part of a "redis://" URL (https://www.iana.org/assignments/uri-schemes/prov/redis), and TLS can be enabled either by setting the TLSConfig in Options or by using a "rediss://" URL (https://www.iana.org/assignments/uri-schemes/prov/rediss).
To use multiple Redis hosts in cluster mode, use Options and set the Addrs field.
Specifying an invalid URL will cause an error when the SDK is started.