redis_cluster

Redis cluster module.

exception spicerack.redis_cluster.RedisClusterError[source]

Bases: 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) None[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 (pathlib.Path) -- path to the directory containing the configuration files for the Redis clusters.

  • dry_run (bool, default: True) -- 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:

spicerack.redis.RedisClusterError -- on error and invalid parameters.

Return type:

None

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:

spicerack.redis.RedisClusterError -- on error.

Return type:

None

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

Bases: object

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

Initialize the instance.

Parameters:

**kwargs (typing.Any) -- 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.

Return type:

None

stop_replica() None[source]

Stop the replica on the instance.

Return type:

None

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.

property is_master: bool

Returns True if the current instance is a master, False otherwise.

property master_info: 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.