summaryrefslogtreecommitdiff
path: root/redis/cluster.py
diff options
context:
space:
mode:
authorUtkarsh Gupta <utkarshgupta137@gmail.com>2022-05-30 19:04:06 +0530
committerGitHub <noreply@github.com>2022-05-30 16:34:06 +0300
commitf704281cf4c1f735c06a13946fcea42fa939e3a5 (patch)
tree85a7affc680058b54d1df30d65e1f97c44c08847 /redis/cluster.py
parent48079083a7f6ac1bdd948c03175f9ffd42aa1f6b (diff)
downloadredis-py-f704281cf4c1f735c06a13946fcea42fa939e3a5.tar.gz
async_cluster: add/update typing (#2195)
* async_cluster: add/update typing * async_cluster: update cleanup_kwargs with kwargs from async Connection * async_cluster: properly remove old nodes
Diffstat (limited to 'redis/cluster.py')
-rw-r--r--redis/cluster.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/redis/cluster.py b/redis/cluster.py
index 0b9c543..46a96a6 100644
--- a/redis/cluster.py
+++ b/redis/cluster.py
@@ -6,6 +6,7 @@ import sys
import threading
import time
from collections import OrderedDict
+from typing import Any, Dict, Tuple
from redis.client import CaseInsensitiveDict, PubSub, Redis, parse_scan
from redis.commands import CommandsParser, RedisClusterCommands
@@ -40,7 +41,7 @@ from redis.utils import (
log = logging.getLogger(__name__)
-def get_node_name(host, port):
+def get_node_name(host: str, port: int) -> str:
return f"{host}:{port}"
@@ -74,10 +75,12 @@ def parse_pubsub_numsub(command, res, **options):
return ret_numsub
-def parse_cluster_slots(resp, **options):
+def parse_cluster_slots(
+ resp: Any, **options: Any
+) -> Dict[Tuple[int, int], Dict[str, Any]]:
current_host = options.get("current_host", "")
- def fix_server(*args):
+ def fix_server(*args: Any) -> Tuple[str, Any]:
return str_if_bytes(args[0]) or current_host, args[1]
slots = {}
@@ -1248,17 +1251,17 @@ class LoadBalancer:
Round-Robin Load Balancing
"""
- def __init__(self, start_index=0):
+ def __init__(self, start_index: int = 0) -> None:
self.primary_to_idx = {}
self.start_index = start_index
- def get_server_index(self, primary, list_size):
+ def get_server_index(self, primary: str, list_size: int) -> int:
server_index = self.primary_to_idx.setdefault(primary, self.start_index)
# Update the index
self.primary_to_idx[primary] = (server_index + 1) % list_size
return server_index
- def reset(self):
+ def reset(self) -> None:
self.primary_to_idx.clear()