Redis cluster module.

class spicerack.redis_cluster.RedisCluster(cluster, config_dir, *, dry_run=True)[source]

Bases: object

Class to manage a Redis Cluster.

Initialize the instance.

  • 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, master_datacenter)[source]

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

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

RedisClusterError -- on error and invalid parameters.


Stop the cluster replica in a datacenter.

Parameters:datacenter (str) -- the datacenter on which to stop the replica.
Raises:RedisClusterError -- on error.
exception spicerack.redis_cluster.RedisClusterError[source]

Bases: spicerack.exceptions.SpicerackError

Custom exception class for errors in the RedisCluster class.

class spicerack.redis_cluster.RedisInstance(**kwargs)[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.

Getter to know the detail of this instance.

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

Getter to check if the current instance is a master.

Returns:True if the instance is a master, False otherwise.
Return type:bool

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

Start the replica from the given master instance.

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

Stop the replica on the instance.