22
33The Python interface to the Redis key-value store.
44
5- [ ![ CI] ( https://github.com/redis/redis-py/workflows/CI/badge.svg?branch=master )] ( https://github.com/redis/redis-py/actions?query=workflow%3ACI+branch%3Amaster )
6- [ ![ docs] ( https://readthedocs.org/projects/redis-py/badge/?version=stable&style=flat )] ( https://redis-py.readthedocs.io/en/stable/ )
7- [ ![ MIT licensed] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( ./LICENSE.txt )
8- [ ![ pypi] ( https://badge.fury.io/py/redis.svg )] ( https://pypi.org/project/redis/ )
5+ [ ![ CI] ( https://github.com/redis/redis-py/workflows/CI/badge.svg?branch=master )] ( https://github.com/redis/redis-py/actions?query=workflow%3ACI+branch%3Amaster )
6+ [ ![ docs] ( https://readthedocs.org/projects/redis-py/badge/?version=stable&style=flat )] ( https://redis-py.readthedocs.io/en/stable/ )
7+ [ ![ MIT licensed] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( ./LICENSE )
8+ [ ![ pypi] ( https://badge.fury.io/py/redis.svg )] ( https://pypi.org/project/redis/ )
99[ ![ codecov] ( https://codecov.io/gh/redis/redis-py/branch/master/graph/badge.svg?token=yenl5fzxxr )] ( https://codecov.io/gh/redis/redis-py )
1010[ ![ Total alerts] ( https://img.shields.io/lgtm/alerts/g/redis/redis-py.svg?logo=lgtm&logoWidth=18 )] ( https://lgtm.com/projects/g/redis/redis-py/alerts/ )
1111
@@ -72,7 +72,7 @@ specified.
7272The default encoding is utf-8, but this can be customized by specifiying the
7373encoding argument for the redis.Redis class.
7474The encoding will be used to automatically encode any
75- strings passed to commands, such as key names and values.
75+ strings passed to commands, such as key names and values.
7676
7777
7878--------------------
@@ -951,16 +951,16 @@ C 3
951951redis-py is now supports cluster mode and provides a client for
952952[ Redis Cluster] ( < https://redis.io/topics/cluster-tutorial > ) .
953953
954- The cluster client is based on Grokzen's
955- [ redis-py-cluster] ( https://github.com/Grokzen/redis-py-cluster ) , has added bug
956- fixes, and now supersedes that library. Support for these changes is thanks to
954+ The cluster client is based on Grokzen's
955+ [ redis-py-cluster] ( https://github.com/Grokzen/redis-py-cluster ) , has added bug
956+ fixes, and now supersedes that library. Support for these changes is thanks to
957957his contributions.
958958
959959
960960** Create RedisCluster:**
961961
962- Connecting redis-py to a Redis Cluster instance(s) requires at a minimum a
963- single node for cluster discovery. There are multiple ways in which a cluster
962+ Connecting redis-py to a Redis Cluster instance(s) requires at a minimum a
963+ single node for cluster discovery. There are multiple ways in which a cluster
964964instance can be created:
965965
966966- Using 'host' and 'port' arguments:
@@ -1001,16 +1001,16 @@ RedisCluster instance can be directly used to execute Redis commands. When a
10011001command is being executed through the cluster instance, the target node(s) will
10021002be internally determined. When using a key-based command, the target node will
10031003be the node that holds the key's slot.
1004- Cluster management commands and other commands that are not key-based have a
1005- parameter called 'target_nodes' where you can specify which nodes to execute
1006- the command on. In the absence of target_nodes, the command will be executed
1007- on the default cluster node. As part of cluster instance initialization, the
1008- cluster's default node is randomly selected from the cluster's primaries, and
1009- will be updated upon reinitialization. Using r.get_default_node(), you can
1010- get the cluster's default node, or you can change it using the
1004+ Cluster management commands and other commands that are not key-based have a
1005+ parameter called 'target_nodes' where you can specify which nodes to execute
1006+ the command on. In the absence of target_nodes, the command will be executed
1007+ on the default cluster node. As part of cluster instance initialization, the
1008+ cluster's default node is randomly selected from the cluster's primaries, and
1009+ will be updated upon reinitialization. Using r.get_default_node(), you can
1010+ get the cluster's default node, or you can change it using the
10111011'set_default_node' method.
10121012
1013- The 'target_nodes' parameter is explained in the following section,
1013+ The 'target_nodes' parameter is explained in the following section,
10141014'Specifying Target Nodes'.
10151015
10161016``` pycon
@@ -1030,8 +1030,8 @@ The 'target_nodes' parameter is explained in the following section,
10301030
10311031** Specifying Target Nodes:**
10321032
1033- As mentioned above, all non key-based RedisCluster commands accept the kwarg
1034- parameter 'target_nodes' that specifies the node/nodes that the command should
1033+ As mentioned above, all non key-based RedisCluster commands accept the kwarg
1034+ parameter 'target_nodes' that specifies the node/nodes that the command should
10351035be executed on.
10361036The best practice is to specify target nodes using RedisCluster class's node
10371037flags: PRIMARIES, REPLICAS, ALL_NODES, RANDOM. When a nodes flag is passed
@@ -1070,7 +1070,7 @@ the relevant cluster or connection error will be returned.
10701070 >>> rc.info(target_nodes=subset_primaries)
10711071```
10721072
1073- In addition, the RedisCluster instance can query the Redis instance of a
1073+ In addition, the RedisCluster instance can query the Redis instance of a
10741074specific node and execute commands on that node directly. The Redis client,
10751075however, does not handle cluster failures and retries.
10761076
@@ -1094,7 +1094,7 @@ By using RedisCluster client, you can use the known functions (e.g. mget, mset)
10941094to perform an atomic multi-key operation. However, you must ensure all keys are
10951095mapped to the same slot, otherwise a RedisClusterException will be thrown.
10961096Redis Cluster implements a concept called hash tags that can be used in order
1097- to force certain keys to be stored in the same hash slot, see
1097+ to force certain keys to be stored in the same hash slot, see
10981098[ Keys hash tag] ( https://redis.io/topics/cluster-spec#keys-hash-tags ) .
10991099You can also use nonatomic for some of the multikey operations, and pass keys
11001100that aren't mapped to the same slot. The client will then map the keys to the
@@ -1121,15 +1121,15 @@ first command execution. The node will be determined by:
11211121 1 . Hashing the channel name in the request to find its keyslot
11221122 2 . Selecting a node that handles the keyslot: If read_from_replicas is
11231123 set to true, a replica can be selected.
1124-
1124+
11251125* Known limitations with pubsub:*
11261126
1127- Pattern subscribe and publish do not currently work properly due to key slots.
1128- If we hash a pattern like fo* we will receive a keyslot for that string but
1129- there are endless possibilities for channel names based on this pattern -
1130- unknowable in advance. This feature is not disabled but the commands are not
1127+ Pattern subscribe and publish do not currently work properly due to key slots.
1128+ If we hash a pattern like fo* we will receive a keyslot for that string but
1129+ there are endless possibilities for channel names based on this pattern -
1130+ unknowable in advance. This feature is not disabled but the commands are not
11311131currently recommended for use.
1132- See [ redis-py-cluster documentation] ( https://redis-py-cluster.readthedocs.io/en/stable/pubsub.html )
1132+ See [ redis-py-cluster documentation] ( https://redis-py-cluster.readthedocs.io/en/stable/pubsub.html )
11331133 for more.
11341134
11351135``` pycon
@@ -1142,22 +1142,22 @@ See [redis-py-cluster documentation](https://redis-py-cluster.readthedocs.io/en/
11421142
11431143** Read Only Mode**
11441144
1145- By default, Redis Cluster always returns MOVE redirection response on accessing
1146- a replica node. You can overcome this limitation and scale read commands by
1145+ By default, Redis Cluster always returns MOVE redirection response on accessing
1146+ a replica node. You can overcome this limitation and scale read commands by
11471147triggering READONLY mode.
11481148
1149- To enable READONLY mode pass read_from_replicas=True to RedisCluster
1149+ To enable READONLY mode pass read_from_replicas=True to RedisCluster
11501150constructor. When set to true, read commands will be assigned between the
1151- primary and its replications in a Round-Robin manner.
1151+ primary and its replications in a Round-Robin manner.
11521152
1153- READONLY mode can be set at runtime by calling the readonly() method with
1154- target_nodes='replicas', and read-write access can be restored by calling the
1153+ READONLY mode can be set at runtime by calling the readonly() method with
1154+ target_nodes='replicas', and read-write access can be restored by calling the
11551155readwrite() method.
11561156
11571157``` pycon
11581158 >>> from cluster import RedisCluster as Redis
11591159 # Use 'debug' log level to print the node that the command is executed on
1160- >>> rc_readonly = Redis(startup_nodes=startup_nodes,
1160+ >>> rc_readonly = Redis(startup_nodes=startup_nodes,
11611161 read_from_replicas=True)
11621162 >>> rc_readonly.set('{foo}1', 'bar1')
11631163 >>> for i in range(0, 4):
@@ -1173,15 +1173,15 @@ readwrite() method.
11731173
11741174** Cluster Pipeline**
11751175
1176- ClusterPipeline is a subclass of RedisCluster that provides support for Redis
1177- pipelines in cluster mode.
1178- When calling the execute() command, all the commands are grouped by the node
1179- on which they will be executed, and are then executed by the respective nodes
1180- in parallel. The pipeline instance will wait for all the nodes to respond
1181- before returning the result to the caller. Command responses are returned as a
1176+ ClusterPipeline is a subclass of RedisCluster that provides support for Redis
1177+ pipelines in cluster mode.
1178+ When calling the execute() command, all the commands are grouped by the node
1179+ on which they will be executed, and are then executed by the respective nodes
1180+ in parallel. The pipeline instance will wait for all the nodes to respond
1181+ before returning the result to the caller. Command responses are returned as a
11821182list sorted in the same order in which they were sent.
1183- Pipelines can be used to dramatically increase the throughput of Redis Cluster
1184- by significantly reducing the the number of network round trips between the
1183+ Pipelines can be used to dramatically increase the throughput of Redis Cluster
1184+ by significantly reducing the the number of network round trips between the
11851185client and the server.
11861186
11871187``` pycon
@@ -1198,16 +1198,16 @@ client and the server.
11981198Please note:
11991199- RedisCluster pipelines currently only support key-based commands.
12001200- The pipeline gets its 'read_from_replicas' value from the cluster's parameter.
1201- Thus, if read from replications is enabled in the cluster instance, the pipeline
1201+ Thus, if read from replications is enabled in the cluster instance, the pipeline
12021202will also direct read commands to replicas.
1203- - The 'transcation' option is NOT supported in cluster-mode. In non-cluster mode,
1204- the 'transaction' option is available when executing pipelines. This wraps the
1205- pipeline commands with MULTI/EXEC commands, and effectively turns the pipeline
1206- commands into a single transaction block. This means that all commands are
1207- executed sequentially without any interruptions from other clients. However,
1208- in cluster-mode this is not possible, because commands are partitioned
1209- according to their respective destination nodes. This means that we can not
1210- turn the pipeline commands into one transaction block, because in most cases
1203+ - The 'transcation' option is NOT supported in cluster-mode. In non-cluster mode,
1204+ the 'transaction' option is available when executing pipelines. This wraps the
1205+ pipeline commands with MULTI/EXEC commands, and effectively turns the pipeline
1206+ commands into a single transaction block. This means that all commands are
1207+ executed sequentially without any interruptions from other clients. However,
1208+ in cluster-mode this is not possible, because commands are partitioned
1209+ according to their respective destination nodes. This means that we can not
1210+ turn the pipeline commands into one transaction block, because in most cases
12111211they are split up into several smaller pipelines.
12121212
12131213
0 commit comments