Skip to content

Commit 143107a

Browse files
enjoy-binbinchayimdvora-h
authored
Cluster commands linkdocs (#2069)
* Link documentation for all cluster commands Added links to the documentation in the docstrings in redis/commands/cluster.py Part of #1712 * copy stralgo comment from commands/core.py to commands/cluster.py * fix linters Co-authored-by: enjoy-binbin <binbin.zhu@tenclass.com> Co-authored-by: Chayim I. Kirshen <c@kirshen.com> Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>
1 parent d4fcd99 commit 143107a

File tree

2 files changed

+348
-263
lines changed

2 files changed

+348
-263
lines changed

redis/commands/cluster.py

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def mget_nonatomic(self, keys, *args):
4141
if keys belong to more than one slot.
4242
4343
Returns a list of values ordered identically to ``keys``
44+
45+
For more information see https://redis.io/commands/mget
4446
"""
4547

4648
from redis.client import EMPTY_RESPONSE
@@ -77,6 +79,8 @@ def mset_nonatomic(self, mapping):
7779
Splits the keys into different slots and then calls MSET
7880
for the keys of every slot. This operation will not be atomic
7981
if keys belong to more than one slot.
82+
83+
For more information see https://redis.io/commands/mset
8084
"""
8185

8286
# Partition the keys by slot
@@ -115,6 +119,8 @@ def exists(self, *keys):
115119
Returns the number of ``names`` that exist in the
116120
whole cluster. The keys are first split up into slots
117121
and then an EXISTS command is sent for every slot
122+
123+
For more information see https://redis.io/commands/exists
118124
"""
119125
return self._split_command_across_slots("EXISTS", *keys)
120126

@@ -126,6 +132,8 @@ def delete(self, *keys):
126132
127133
Non-existant keys are ignored.
128134
Returns the number of keys that were deleted.
135+
136+
For more information see https://redis.io/commands/del
129137
"""
130138
return self._split_command_across_slots("DEL", *keys)
131139

@@ -139,6 +147,8 @@ def touch(self, *keys):
139147
140148
Non-existant keys are ignored.
141149
Returns the number of keys that were touched.
150+
151+
For more information see https://redis.io/commands/touch
142152
"""
143153
return self._split_command_across_slots("TOUCH", *keys)
144154

@@ -151,6 +161,8 @@ def unlink(self, *keys):
151161
152162
Non-existant keys are ignored.
153163
Returns the number of keys that were unlinked.
164+
165+
For more information see https://redis.io/commands/unlink
154166
"""
155167
return self._split_command_across_slots("UNLINK", *keys)
156168

@@ -164,12 +176,27 @@ class ClusterManagementCommands(ManagementCommands):
164176
"""
165177

166178
def slaveof(self, *args, **kwargs):
179+
"""
180+
Make the server a replica of another instance, or promote it as master.
181+
182+
For more information see https://redis.io/commands/slaveof
183+
"""
167184
raise RedisClusterException("SLAVEOF is not supported in cluster mode")
168185

169186
def replicaof(self, *args, **kwargs):
187+
"""
188+
Make the server a replica of another instance, or promote it as master.
189+
190+
For more information see https://redis.io/commands/replicaof
191+
"""
170192
raise RedisClusterException("REPLICAOF is not supported in cluster" " mode")
171193

172194
def swapdb(self, *args, **kwargs):
195+
"""
196+
Swaps two Redis databases.
197+
198+
For more information see https://redis.io/commands/swapdb
199+
"""
173200
raise RedisClusterException("SWAPDB is not supported in cluster" " mode")
174201

175202

@@ -193,6 +220,25 @@ def stralgo(
193220
withmatchlen=False,
194221
**kwargs,
195222
):
223+
"""
224+
Implements complex algorithms that operate on strings.
225+
Right now the only algorithm implemented is the LCS algorithm
226+
(longest common substring). However new algorithms could be
227+
implemented in the future.
228+
229+
``algo`` Right now must be LCS
230+
``value1`` and ``value2`` Can be two strings or two keys
231+
``specific_argument`` Specifying if the arguments to the algorithm
232+
will be keys or strings. strings is the default.
233+
``len`` Returns just the len of the match.
234+
``idx`` Returns the match positions in each string.
235+
``minmatchlen`` Restrict the list of matches to the ones of a given
236+
minimal length. Can be provided only when ``idx`` set to True.
237+
``withmatchlen`` Returns the matches with the len of the match.
238+
Can be provided only when ``idx`` set to True.
239+
240+
For more information see https://redis.io/commands/stralgo
241+
"""
196242
target_nodes = kwargs.pop("target_nodes", None)
197243
if specific_argument == "strings" and target_nodes is None:
198244
target_nodes = "default-node"
@@ -292,6 +338,8 @@ def cluster_addslots(self, target_node, *slots):
292338
293339
:target_node: 'ClusterNode'
294340
The node to execute the command on
341+
342+
For more information see https://redis.io/commands/cluster-addslots
295343
"""
296344
return self.execute_command(
297345
"CLUSTER ADDSLOTS", *slots, target_nodes=target_node
@@ -307,7 +355,7 @@ def cluster_addslotsrange(self, target_node, *slots):
307355
:target_node: 'ClusterNode'
308356
The node to execute the command on
309357
310-
For more information check https://redis.io/commands/cluster-addslotsrange
358+
For more information see https://redis.io/commands/cluster-addslotsrange
311359
"""
312360
return self.execute_command(
313361
"CLUSTER ADDSLOTSRANGE", *slots, target_nodes=target_node
@@ -317,13 +365,17 @@ def cluster_countkeysinslot(self, slot_id):
317365
"""
318366
Return the number of local keys in the specified hash slot
319367
Send to node based on specified slot_id
368+
369+
For more information see https://redis.io/commands/cluster-countkeysinslot
320370
"""
321371
return self.execute_command("CLUSTER COUNTKEYSINSLOT", slot_id)
322372

323373
def cluster_count_failure_report(self, node_id):
324374
"""
325375
Return the number of failure reports active for a given node
326376
Sends to a random node
377+
378+
For more information see https://redis.io/commands/cluster-count-failure-reports
327379
"""
328380
return self.execute_command("CLUSTER COUNT-FAILURE-REPORTS", node_id)
329381

@@ -333,6 +385,8 @@ def cluster_delslots(self, *slots):
333385
It determines by it self what node the slot is in and sends it there
334386
335387
Returns a list of the results for each processed slot.
388+
389+
For more information see https://redis.io/commands/cluster-delslots
336390
"""
337391
return [self.execute_command("CLUSTER DELSLOTS", slot) for slot in slots]
338392

@@ -343,7 +397,7 @@ def cluster_delslotsrange(self, *slots):
343397
from the node, while CLUSTER DELSLOTSRANGE takes a list of slot ranges to remove
344398
from the node.
345399
346-
For more information check https://redis.io/commands/cluster-delslotsrange
400+
For more information see https://redis.io/commands/cluster-delslotsrange
347401
"""
348402
return self.execute_command("CLUSTER DELSLOTSRANGE", *slots)
349403

@@ -354,6 +408,8 @@ def cluster_failover(self, target_node, option=None):
354408
355409
:target_node: 'ClusterNode'
356410
The node to execute the command on
411+
412+
For more information see https://redis.io/commands/cluster-failover
357413
"""
358414
if option:
359415
if option.upper() not in ["FORCE", "TAKEOVER"]:
@@ -372,36 +428,45 @@ def cluster_info(self, target_nodes=None):
372428
Provides info about Redis Cluster node state.
373429
The command will be sent to a random node in the cluster if no target
374430
node is specified.
431+
432+
For more information see https://redis.io/commands/cluster-info
375433
"""
376434
return self.execute_command("CLUSTER INFO", target_nodes=target_nodes)
377435

378436
def cluster_keyslot(self, key):
379437
"""
380438
Returns the hash slot of the specified key
381439
Sends to random node in the cluster
440+
441+
For more information see https://redis.io/commands/cluster-keyslot
382442
"""
383443
return self.execute_command("CLUSTER KEYSLOT", key)
384444

385445
def cluster_meet(self, host, port, target_nodes=None):
386446
"""
387447
Force a node cluster to handshake with another node.
388448
Sends to specified node.
449+
450+
For more information see https://redis.io/commands/cluster-meet
389451
"""
390452
return self.execute_command(
391453
"CLUSTER MEET", host, port, target_nodes=target_nodes
392454
)
393455

394456
def cluster_nodes(self):
395457
"""
396-
Force a node cluster to handshake with another node
397-
458+
Get Cluster config for the node.
398459
Sends to random node in the cluster
460+
461+
For more information see https://redis.io/commands/cluster-nodes
399462
"""
400463
return self.execute_command("CLUSTER NODES")
401464

402465
def cluster_replicate(self, target_nodes, node_id):
403466
"""
404467
Reconfigure a node as a slave of the specified master node
468+
469+
For more information see https://redis.io/commands/cluster-replicate
405470
"""
406471
return self.execute_command(
407472
"CLUSTER REPLICATE", node_id, target_nodes=target_nodes
@@ -413,6 +478,8 @@ def cluster_reset(self, soft=True, target_nodes=None):
413478
414479
If 'soft' is True then it will send 'SOFT' argument
415480
If 'soft' is False then it will send 'HARD' argument
481+
482+
For more information see https://redis.io/commands/cluster-reset
416483
"""
417484
return self.execute_command(
418485
"CLUSTER RESET", b"SOFT" if soft else b"HARD", target_nodes=target_nodes
@@ -421,18 +488,24 @@ def cluster_reset(self, soft=True, target_nodes=None):
421488
def cluster_save_config(self, target_nodes=None):
422489
"""
423490
Forces the node to save cluster state on disk
491+
492+
For more information see https://redis.io/commands/cluster-saveconfig
424493
"""
425494
return self.execute_command("CLUSTER SAVECONFIG", target_nodes=target_nodes)
426495

427496
def cluster_get_keys_in_slot(self, slot, num_keys):
428497
"""
429498
Returns the number of keys in the specified cluster slot
499+
500+
For more information see https://redis.io/commands/cluster-getkeysinslot
430501
"""
431502
return self.execute_command("CLUSTER GETKEYSINSLOT", slot, num_keys)
432503

433504
def cluster_set_config_epoch(self, epoch, target_nodes=None):
434505
"""
435506
Set the configuration epoch in a new node
507+
508+
For more information see https://redis.io/commands/cluster-set-config-epoch
436509
"""
437510
return self.execute_command(
438511
"CLUSTER SET-CONFIG-EPOCH", epoch, target_nodes=target_nodes
@@ -444,6 +517,8 @@ def cluster_setslot(self, target_node, node_id, slot_id, state):
444517
445518
:target_node: 'ClusterNode'
446519
The node to execute the command on
520+
521+
For more information see https://redis.io/commands/cluster-setslot
447522
"""
448523
if state.upper() in ("IMPORTING", "NODE", "MIGRATING"):
449524
return self.execute_command(
@@ -458,13 +533,17 @@ def cluster_setslot_stable(self, slot_id):
458533
"""
459534
Clears migrating / importing state from the slot.
460535
It determines by it self what node the slot is in and sends it there.
536+
537+
For more information see https://redis.io/commands/cluster-setslot
461538
"""
462539
return self.execute_command("CLUSTER SETSLOT", slot_id, "STABLE")
463540

464541
def cluster_replicas(self, node_id, target_nodes=None):
465542
"""
466543
Provides a list of replica nodes replicating from the specified primary
467544
target node.
545+
546+
For more information see https://redis.io/commands/cluster-replicas
468547
"""
469548
return self.execute_command(
470549
"CLUSTER REPLICAS", node_id, target_nodes=target_nodes
@@ -473,6 +552,8 @@ def cluster_replicas(self, node_id, target_nodes=None):
473552
def cluster_slots(self, target_nodes=None):
474553
"""
475554
Get array of Cluster slot to node mappings
555+
556+
For more information see https://redis.io/commands/cluster-slots
476557
"""
477558
return self.execute_command("CLUSTER SLOTS", target_nodes=target_nodes)
478559

@@ -484,7 +565,7 @@ def cluster_links(self, target_node):
484565
485566
This command outputs information of all such peer links as an array.
486567
487-
For more information check https://redis.io/commands/cluster-links
568+
For more information see https://redis.io/commands/cluster-links
488569
"""
489570
return self.execute_command("CLUSTER LINKS", target_nodes=target_node)
490571

@@ -493,6 +574,8 @@ def readonly(self, target_nodes=None):
493574
Enables read queries.
494575
The command will be sent to the default cluster node if target_nodes is
495576
not specified.
577+
578+
For more information see https://redis.io/commands/readonly
496579
"""
497580
if target_nodes == "replicas" or target_nodes == "all":
498581
# read_from_replicas will only be enabled if the READONLY command
@@ -505,6 +588,8 @@ def readwrite(self, target_nodes=None):
505588
Disables read queries.
506589
The command will be sent to the default cluster node if target_nodes is
507590
not specified.
591+
592+
For more information see https://redis.io/commands/readwrite
508593
"""
509594
# Reset read from replicas flag
510595
self.read_from_replicas = False

0 commit comments

Comments
 (0)