Crates.io | launchdarkly-server-sdk-redis |
lib.rs | launchdarkly-server-sdk-redis |
version | 1.0.0-rc.1 |
source | src |
created_at | 2023-01-11 19:55:03.833022 |
updated_at | 2023-01-11 19:55:03.833022 |
description | LaunchDarkly Server-Side SDK - Redis Integration |
homepage | https://docs.launchdarkly.com/sdk/server-side/rust |
repository | https://github.com/launchdarkly/rust-server-sdk-redis |
max_upload_size | |
id | 756679 |
size | 44,681 |
This library provides a Redis-backed persistence mechanism (data store) for the LaunchDarkly Rust SDK, replacing the default in-memory data store.
The Redis API implementation it uses is redis. There are other Redis client implementations for Rust; if LaunchDarkly SDK Redis integrations using other Redis clients are released, they will be in separate repositories.
For more information, see also: Using a persistent feature store.
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!
This assumes that you have already installed the LaunchDarkly Rust SDK.
use launchdarkly_server_sdk::{Client, ConfigBuilder, PersistentDataStoreBuilder};
use launchdarkly_server_sdk_redis::RedisPersistentDataStoreFactory;
use std::sync::Arc;
ConfigBuilder
with an instance of the PersistentDataStoreBuilder
. You may specify any custom Redis options using the methods of RedisPersistentDataStoreFactory
. For instance, to customize the Redis URL:let mut redis_factory = RedisPersistentDataStoreFactory::new();
redis_factory.url("redis://localhost:9000");
let persistent_data_store_builder = PersistentDataStoreBuilder::new(Arc::new(redis_factory));
let mut config_builder = ConfigBuilder::new(&sdk_key);
config_builder = config_builder.data_store(&persistent_data_store_builder);
By default, the store will try to connect to a local Redis instance on port 6379.
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 in the SDK documentation. For instance, to specify a cache TTL of 5 minutes:
let mut persistent_data_store_builder =
PersistentDataStoreBuilder::new(Arc::new(redis_factory));
persistent_data_store_builder.cache_time(std::time::Duration::from_secs(5 * 60));