redis_cluster

Redis cluster module.

exception spicerack.redis_cluster.RedisClusterError[source]

Bases: spicerack.exceptions.SpicerackError

Custom exception class for errors in the RedisCluster class.

class spicerack.redis_cluster.RedisCluster(cluster: str, config_dir: pathlib.Path, *, dry_run: bool = True)[source]

Bases: object

Class to manage a Redis Cluster.

Initialize the instance.

Parameters
  • cluster (str) -- the name of the cluster to connect to.

  • config_dir (str) -- path to the directory containing the configuration files for the Redis clusters.

  • dry_run (bool, optional) -- whether this is a DRY-RUN.

start_replica(datacenter: str, master_datacenter: str) None[source]

Start the cluster replica in a datacenter from a master datacenter.

Parameters
  • datacenter (str) -- the datacenter on which to start the replica.

  • master_datacenter (str) -- the datacenter from which to replicate.

Raises

RedisClusterError -- on error and invalid parameters.

stop_replica(datacenter: str) None[source]

Stop the cluster replica in a datacenter.

Parameters

datacenter (str) -- the datacenter on which to stop the replica.

Raises

RedisClusterError -- on error.

class spicerack.redis_cluster.RedisInstance(**kwargs: Any)[source]

Bases: object

Class to manage a Redis instance, a simple wrapper around redis.StrictRedis.

Initialize the instance.

Parameters

**kwargs (mixed) -- arbitrary keyword arguments, to be passed to the redis.StrictRedis constructor.

start_replica(master: spicerack.redis_cluster.RedisInstance) None[source]

Start the replica from the given master instance.

Parameters

master (spicerack.redis_cluster.RedisInstance) -- the master instance.

stop_replica() None[source]

Stop the replica on the instance.

property info: Tuple[str, int]

Getter to know the detail of this instance.

Returns

a 2-element tuple with (host/IP, port) of the instance.

Return type

tuple

property is_master: bool

Getter to check if the current instance is a master.

Returns

True if the instance is a master, False otherwise.

Return type

bool

property master_info: Union[Tuple[None, None], Tuple[str, int]]

Getter to know the master of this instance.

Returns

a 2-element tuple with (host/IP, port) of the master instance. If there is no master configured (None, None) is returned.

Return type

tuple