Class: RedisSingleFile::ClusterClientBuilder
- Inherits:
-
Object
- Object
- RedisSingleFile::ClusterClientBuilder
- Defined in:
- lib/redis_single_file/cluster_client_builder.rb
Overview
This class is a cluster client builder that performs automatic cluster detection and redis client conversion. All params from the original non-cluster client will be transfered to the new cluster-enabled client when building the new client.
Class Method Summary collapse
-
.call ⇒ Redis::Cluster
Delegates class method calls to instance method.
Instance Method Summary collapse
-
#call ⇒ Redis::Cluster
Convert standard redis client to a cluster-enabled client.
-
#initialize(redis:) ⇒ self
constructor
Cluster client builder instance.
Constructor Details
#initialize(redis:) ⇒ self
redis: Standard redis client instance for a clustered environment. The cluster information will be extracted from this client when creating the new cluster-enabled client so must responsd to cluster commands and have an enabled cluster configured.
Returns cluster client builder instance.
30 31 32 |
# File 'lib/redis_single_file/cluster_client_builder.rb', line 30 def initialize(redis:) @redis = redis end |
Class Method Details
.call ⇒ Redis::Cluster
Delegates class method calls to instance method
20 |
# File 'lib/redis_single_file/cluster_client_builder.rb', line 20 def call(...) = new(...).call |
Instance Method Details
#call ⇒ Redis::Cluster
Convert standard redis client to a cluster-enabled client. Client options are extracted from the original client and passed to the new client along with parsed nodes from original client’s cluster configuration.
40 41 42 43 44 45 |
# File 'lib/redis_single_file/cluster_client_builder.rb', line 40 def call raise ClusterDisabledError, 'cluster not detected' unless cluster_enabled? # use extracted client options with parsed master nodes Redis::Cluster.new(**, nodes: master_nodes) end |