C++ Server-Side SDK Redis Source
Provide SDK data via Redis
Classes | Macros | Typedefs | Functions
redis_source.h File Reference

LaunchDarkly Server-side Redis Source C Binding. More...

#include <launchdarkly/bindings/c/export.h>
Include dependency graph for redis_source.h:

Go to the source code of this file.

Classes

struct  LDServerLazyLoadRedisResult
 Stores the result of calling LDDServerLazyLoadRedisSource_New. More...
 

Macros

#define LDSERVER_LAZYLOAD_REDISSOURCE_ERROR_MESSAGE_SIZE   256
 

Typedefs

typedef struct _LDServerLazyLoadRedisSource * LDServerLazyLoadRedisSource
 LDServerLazyLoadRedisSource represents a data source for the Server-Side SDK backed by Redis. It is meant to be used in place of the standard LaunchDarkly Streaming or Polling data sources. More...
 

Functions

 LDServerLazyLoadRedisSource_New (char const *uri, char const *prefix, struct LDServerLazyLoadRedisResult *out_result)
 Creates a new Redis data source suitable for usage in the SDK's Lazy Load data system. More...
 
 LDServerLazyLoadRedisSource_Free (LDServerLazyLoadRedisSource source)
 Frees a Redis data source pointer. Only necessary to call if not passing ownership to SDK configuration.
 

Detailed Description

LaunchDarkly Server-side Redis Source C Binding.

Typedef Documentation

◆ LDServerLazyLoadRedisSource

typedef struct _LDServerLazyLoadRedisSource* LDServerLazyLoadRedisSource

LDServerLazyLoadRedisSource represents a data source for the Server-Side SDK backed by Redis. It is meant to be used in place of the standard LaunchDarkly Streaming or Polling data sources.

Call LDServerLazyLoadRedisSource_New to obtain a new instance. This instance can be passed into the SDK's DataSystem configuration via the LazyLoad builder.

Example:

// Stack allocate the result struct, which will hold the result pointer or
// an error message.
// Create the Redis source, passing in arguments for the URI, prefix, and
// pointer to the result.
if (!LDServerLazyLoadRedisSource_New("redis://localhost:6379", "testprefix",
&result)) {
// On failure, you may print the error message (result.error_message),
// then exit or return.
}
// Create a builder for the Lazy Load data system.
LDServerLazyLoadBuilder lazy_builder = LDServerLazyLoadBuilder_New();
// Pass the Redis source pointer into it.
LDServerLazyLoadBuilder_SourcePtr(lazy_builder, result.source);
// Create a standard server-side SDK configuration builder.
LDServerConfigBuilder cfg_builder = LDServerConfigBuilder_New("sdk-123");
// Tell the SDK config builder to use the Lazy Load system that was just
// configured.
LDServerConfigBuilder_DataSystem_LazyLoad(cfg_builder, lazy_builder);
LDServerLazyLoadRedisSource_New(char const *uri, char const *prefix, struct LDServerLazyLoadRedisResult *out_result)
Creates a new Redis data source suitable for usage in the SDK's Lazy Load data system.
Definition: redis_source.cpp:13
Stores the result of calling LDDServerLazyLoadRedisSource_New.
Definition: redis_source.h:76

This implementation is backed by Redis++, a C++ wrapper for the hiredis library.

Function Documentation

◆ LDServerLazyLoadRedisSource_New()

LDServerLazyLoadRedisSource_New ( char const *  uri,
char const *  prefix,
struct LDServerLazyLoadRedisResult out_result 
)

Creates a new Redis data source suitable for usage in the SDK's Lazy Load data system.

In this system, the SDK will query Redis for flag/segment data as required, with an in-memory cache to reduce the number of queries.

Data is never written back to Redis.

Parameters
uriRedis URI string. Must not be NULL or empty string.
prefixPrefix to use when reading SDK data from Redis. This allows multiple SDK environments to coexist in the same database, or for the SDK's data to coexist with other unrelated data. Must not be NULL.
out_resultPointer to struct where the source pointer or an error message should be stored.
Returns
True if the source was created successfully; out_result->source will contain the pointer. The caller must either free the pointer with LDServerLazyLoadRedisSource_Free, OR pass it into the SDK's configuration methods which will take ownership (in which case do not call LDServerLazyLoadRedisSource_Free.)