launchdarkly_server_sdk_redis/lib.rs
1//! launchdarkly-server-sdk-redis provides a Redis-backed persistent data store for the LaunchDarkly Redis SDK.
2//!
3//! For more details about how and why you can use a persistent data store, see:
4//! <https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store>
5//!
6//! To use the Redis data store with the LaunchDarkly client:
7//!
8//! ```rust
9//! use launchdarkly_server_sdk::{Client, ConfigBuilder, PersistentDataStoreBuilder};
10//! use launchdarkly_server_sdk_redis::RedisPersistentDataStoreFactory;
11//! use std::sync::Arc;
12//!
13//! let redis_factory = RedisPersistentDataStoreFactory::new();
14//! let persistent_data_store_builder = PersistentDataStoreBuilder::new(Arc::new(redis_factory));
15//!
16//! # let sdk_key = "example-sdk-key";
17//! let mut config_builder = ConfigBuilder::new(&sdk_key);
18//! config_builder = config_builder.data_store(&persistent_data_store_builder);
19//! ```
20//!
21//! The default Redis configuration uses an address of localhost:6379. You may customize the configuration
22//! by using the methods of the [RedisPersistentDataStoreFactory].
23//!
24//!
25//! ```rust
26//! # use launchdarkly_server_sdk_redis::RedisPersistentDataStoreFactory;
27//! let mut redis_factory = RedisPersistentDataStoreFactory::new();
28//! redis_factory.url("redis://localhost:9999").prefix("new-prefix");
29//! ```
30//!
31//! The SDK provides a caching mechanism on top of the persistent data stores. You can configure
32//! this cache lifetime by calling methods on the [launchdarkly_server_sdk::PersistentDataStoreBuilder] struct.
33//!
34//! ```rust
35//! # use launchdarkly_server_sdk::PersistentDataStoreBuilder;
36//! # use launchdarkly_server_sdk_redis::RedisPersistentDataStoreFactory;
37//! # let redis_factory = RedisPersistentDataStoreFactory::new();
38//! # use std::sync::Arc;
39//! let mut persistent_data_store_builder = PersistentDataStoreBuilder::new(Arc::new(redis_factory));
40//! persistent_data_store_builder.cache_time(std::time::Duration::from_secs(5 * 60));
41//! ```
42//!
43//! Note that some Redis client features can also be specified as part of the URL: redis supports
44//! the redis:// syntax (<https://www.iana.org/assignments/uri-schemes/prov/redis>), which can
45//! include a password and a database number, as well as rediss://
46//! (<https://www.iana.org/assignments/uri-schemes/prov/rediss>), which enables TLS.
47//!
48//! If you are also using Redis for other purposes, the data store can coexist with
49//! other data as long as you are not using the same keys. By default, the keys used by the
50//! data store will always start with "launchdarkly:"; you can change this to another
51//! prefix if desired.
52
53#![deny(rustdoc::missing_crate_level_docs)]
54#![deny(missing_docs)]
55
56mod data_store;
57mod data_store_factory;
58
59pub use data_store_factory::RedisPersistentDataStoreFactory;