redis_cluster¶
Redis cluster module.
-
class
spicerack.redis_cluster.
RedisCluster
(cluster, config_dir, *, dry_run=True)[source]¶ Bases:
object
Class to manage a Redis Cluster.
-
_start_instance_replica
(instance, master)[source]¶ Start the replica in a specific instance from a master instance.
Parameters: - instance (spicerack.redis_cluster.RedisInstance) -- the instance where to start the replica.
- master (spicerack.redis_cluster.RedisInstance) -- the master instance to replicate from.
Raises: RedisClusterError
-- if unable to verify the replica has started.
-
_stop_instance_replica
(instance)[source]¶ Stop the replica in a specific instance.
Parameters: instance (spicerack.redis_cluster.RedisInstance) -- the instance where to stop the replica. Raises: RedisClusterError
-- on error.
-
start_replica
(datacenter, master_datacenter)[source]¶ Start the cluster replica in a datacenter from a master datacenter.
Parameters: Raises: RedisClusterError
-- on error and invalid parameters.
-
stop_replica
(datacenter)[source]¶ 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.
-
__init__
(**kwargs)[source]¶ Initialize the instance.
Parameters: **kwargs (mixed) -- arbitrary keyword arguments, to be passed to the redis.StrictRedis constructor.
-
info
¶ Getter to know the detail of this instance.
Returns: a 2-element tuple with (host/IP, port) of the instance. Return type: tuple
-
is_master
¶ Getter to check if the current instance is a master.
Returns: True if the instance is a master, False otherwise. Return type: bool
-
master_info
¶ 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
-