userver: components::Redis Class Reference
Loading...
Searching...
No Matches
components::Redis Class Reference

#include <userver/storages/redis/component.hpp>

Detailed Description

Redis client component.

Provides access to a redis cluster.

Dynamic options:

Static options:

Name Description Default value
thread_pools.redis_thread_pool_size thread count to serve Redis requests -
thread_pools.sentinel_thread_pool_size thread count to serve sentinel requests. -
groups array of redis clusters to work with excluding subscribers -
groups.[].config_name key name in secdist with options for this cluster -
groups.[].db name to refer to the cluster in components::Redis::GetClient() -
groups.[].sharding_strategy one of RedisCluster, KeyShardCrc32, KeyShardTaximeterCrc32 or KeyShardGpsStorageDriver "KeyShardTaximeterCrc32"
groups.[].allow_reads_from_master allows read requests from master instance false
subscribe_groups array of redis clusters to work with in subscribe mode -
subscribe_groups.[].config_name key name in secdist with options for this cluster -
subscribe_groups.[].db name to refer to the cluster in components::Redis::GetSubscribeClient() -
subscribe_groups.[].sharding_strategy either RedisCluster or KeyShardTaximeterCrc32 "KeyShardTaximeterCrc32"

Static configuration example:

# yaml
redis:
groups:
- config_name: cats
db: hello_service_cats_catalogue
sharding_strategy: RedisCluster
- config_name: dogs
db: hello_service_dogs_catalogue
subscribe_groups:
- config_name: food
db: hello_service_pet_food_orders
thread_pools:
redis_thread_pool_size: 8
sentinel_thread_pool_size: 1

Secdist format

If a config_name option is provided, for example groups.some.config_name: some_name_of_your_database, then the Secdist entry for that alias should look like following:

{
"redis_settings": {
"some_name_of_your_database": {
"password": "the_password_of_your_database",
"sentinels": [
{"host": "the_host1_of_your_database", "port": 11564}
],
"shards": [
{"name": "test_master0"}
]
}
}
}

Cluster Redis setup

Redis cluster is the new recommended way of setting up Redis servers with improved stability.

To start, set sharding_strategy: RedisCluster in the static config as shown above.

Secdist configuration is simplified:

  1. "shards" field is ignored, you can specify an empty array there;
  2. "sentinels" field should contain some of the cluster nodes. They are only used for topology discovery; it is not necessary to list all nodes.
Examples
samples/redis_service/redis_service.cpp.

Definition at line 127 of file component.hpp.

+ Inheritance diagram for components::Redis:
+ Collaboration diagram for components::Redis:

Public Member Functions

 Redis (const ComponentConfig &config, const ComponentContext &component_context)
 
std::shared_ptr< storages::redis::ClientGetClient (const std::string &name, ::redis::RedisWaitConnected wait_connected={}) const
 
std::shared_ptr< redis::Sentinel > Client (const std::string &name) const
 
std::shared_ptr< storages::redis::SubscribeClientGetSubscribeClient (const std::string &name, ::redis::RedisWaitConnected wait_connected={}) const
 
- Public Member Functions inherited from components::ComponentBase
 ComponentBase (const ComponentConfig &, const ComponentContext &)
 
 ComponentBase (ComponentBase &&)=delete
 
 ComponentBase (const ComponentBase &)=delete
 
 ~ComponentBase () override=default
 
ComponentHealth GetComponentHealth () const override
 
void OnLoadingCancelled () override
 
void OnAllComponentsLoaded () override
 
void OnAllComponentsAreStopping () override
 
- Public Member Functions inherited from components::RawComponentBase
 RawComponentBase (RawComponentBase &&)=delete
 
 RawComponentBase (const RawComponentBase &)=delete
 

Static Public Member Functions

static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from components::ComponentBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from components::RawComponentBase
static yaml_config::Schema GetStaticConfigSchema ()
 

Static Public Attributes

static constexpr std::string_view kName = "redis"
 The default name of components::Redis.
 

Additional Inherited Members

- Protected Types inherited from components::ComponentBase
using LoggableComponentBase = ComponentBase
 Legacy alias, use ComponentBase instead.
 

The documentation for this class was generated from the following file: