Class: RedisSingleFile::ClusterClientBuilder

Inherits:
Object
  • Object
show all
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.

Returns:

  • (self)

    the custer_client instance

Author:

  • lifeBCE

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis:) ⇒ self

Note:

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

.callRedis::Cluster

Delegates class method calls to instance method

Parameters:

  • params (...)

    passed directly to constructor

Returns:

  • (Redis::Cluster)

    redis cluster instance



20
# File 'lib/redis_single_file/cluster_client_builder.rb', line 20

def call(...) = new(...).call

Instance Method Details

#callRedis::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.

Returns:

  • (Redis::Cluster)

    redis cluster instance

Raises:



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(**client_options, nodes: master_nodes)
end