2
2
3
3
The Python interface to the Redis key-value store.
4
4
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/ )
9
9
[ ![ codecov] ( https://codecov.io/gh/redis/redis-py/branch/master/graph/badge.svg?token=yenl5fzxxr )] ( https://codecov.io/gh/redis/redis-py )
10
10
[ ![ 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/ )
11
11
@@ -72,7 +72,7 @@ specified.
72
72
The default encoding is utf-8, but this can be customized by specifiying the
73
73
encoding argument for the redis.Redis class.
74
74
The 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.
76
76
77
77
78
78
--------------------
@@ -951,16 +951,16 @@ C 3
951
951
redis-py is now supports cluster mode and provides a client for
952
952
[ Redis Cluster] ( < https://redis.io/topics/cluster-tutorial > ) .
953
953
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
957
957
his contributions.
958
958
959
959
960
960
** Create RedisCluster:**
961
961
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
964
964
instance can be created:
965
965
966
966
- Using 'host' and 'port' arguments:
@@ -1001,16 +1001,16 @@ RedisCluster instance can be directly used to execute Redis commands. When a
1001
1001
command is being executed through the cluster instance, the target node(s) will
1002
1002
be internally determined. When using a key-based command, the target node will
1003
1003
be 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
1011
1011
'set_default_node' method.
1012
1012
1013
- The 'target_nodes' parameter is explained in the following section,
1013
+ The 'target_nodes' parameter is explained in the following section,
1014
1014
'Specifying Target Nodes'.
1015
1015
1016
1016
``` pycon
@@ -1030,8 +1030,8 @@ The 'target_nodes' parameter is explained in the following section,
1030
1030
1031
1031
** Specifying Target Nodes:**
1032
1032
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
1035
1035
be executed on.
1036
1036
The best practice is to specify target nodes using RedisCluster class's node
1037
1037
flags: PRIMARIES, REPLICAS, ALL_NODES, RANDOM. When a nodes flag is passed
@@ -1070,7 +1070,7 @@ the relevant cluster or connection error will be returned.
1070
1070
>>> rc.info(target_nodes=subset_primaries)
1071
1071
```
1072
1072
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
1074
1074
specific node and execute commands on that node directly. The Redis client,
1075
1075
however, does not handle cluster failures and retries.
1076
1076
@@ -1094,7 +1094,7 @@ By using RedisCluster client, you can use the known functions (e.g. mget, mset)
1094
1094
to perform an atomic multi-key operation. However, you must ensure all keys are
1095
1095
mapped to the same slot, otherwise a RedisClusterException will be thrown.
1096
1096
Redis 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
1098
1098
[ Keys hash tag] ( https://redis.io/topics/cluster-spec#keys-hash-tags ) .
1099
1099
You can also use nonatomic for some of the multikey operations, and pass keys
1100
1100
that 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:
1121
1121
1 . Hashing the channel name in the request to find its keyslot
1122
1122
2 . Selecting a node that handles the keyslot: If read_from_replicas is
1123
1123
set to true, a replica can be selected.
1124
-
1124
+
1125
1125
* Known limitations with pubsub:*
1126
1126
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
1131
1131
currently 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 )
1133
1133
for more.
1134
1134
1135
1135
``` pycon
@@ -1142,22 +1142,22 @@ See [redis-py-cluster documentation](https://redis-py-cluster.readthedocs.io/en/
1142
1142
1143
1143
** Read Only Mode**
1144
1144
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
1147
1147
triggering READONLY mode.
1148
1148
1149
- To enable READONLY mode pass read_from_replicas=True to RedisCluster
1149
+ To enable READONLY mode pass read_from_replicas=True to RedisCluster
1150
1150
constructor. 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.
1152
1152
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
1155
1155
readwrite() method.
1156
1156
1157
1157
``` pycon
1158
1158
>>> from cluster import RedisCluster as Redis
1159
1159
# 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,
1161
1161
read_from_replicas=True)
1162
1162
>>> rc_readonly.set('{foo}1', 'bar1')
1163
1163
>>> for i in range(0, 4):
@@ -1173,15 +1173,15 @@ readwrite() method.
1173
1173
1174
1174
** Cluster Pipeline**
1175
1175
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
1182
1182
list 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
1185
1185
client and the server.
1186
1186
1187
1187
``` pycon
@@ -1198,16 +1198,16 @@ client and the server.
1198
1198
Please note:
1199
1199
- RedisCluster pipelines currently only support key-based commands.
1200
1200
- 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
1202
1202
will 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
1211
1211
they are split up into several smaller pipelines.
1212
1212
1213
1213
0 commit comments