Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Add rediscluster support #573

Merged
merged 28 commits into from
May 19, 2021
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7492d69
Add redisc cluster client support
Mar 8, 2021
e9b646a
Add integration tests for ClusterRedisClient
Mar 8, 2021
6050bc3
remove unused import
Mar 8, 2021
8d5d40b
remove unnneeded comment
Mar 8, 2021
cb95feb
remove unused import
Mar 8, 2021
9655d17
disable pylint warning
Mar 8, 2021
6214d10
Update baseplate/clients/redis.py
FranGM Mar 8, 2021
78dc569
Update baseplate/clients/redis.py
FranGM Mar 8, 2021
1765def
address comments
Mar 10, 2021
ffdecf9
set version
Mar 10, 2021
9570abf
Update baseplate/clients/redis_cluster.py
FranGM Mar 10, 2021
df35f03
address comments (take 2)
Mar 11, 2021
94914ae
When read_from_replicas is enabled also read from master
Mar 11, 2021
191ed5d
Return only one node on get_node_by_slot
FranGM Mar 30, 2021
c78dcf2
fix documentation lint issues
FranGM Mar 30, 2021
8db95aa
change some client defaults
FranGM Mar 30, 2021
024adff
add more tests
FranGM Mar 30, 2021
b904a82
Remove unused metric
Apr 6, 2021
aeb416d
pass read_from_replicas arg when creating pipeline
FranGM Apr 20, 2021
2c099df
bump redis-py-cluster version
FranGM Apr 20, 2021
1ee4bdc
Add hot key tracker to the cluster reddis client
Apr 29, 2021
35839ad
Merge branch 'rediscluster-support' of github.com:FranGM/baseplate.py…
Apr 29, 2021
4255cf2
Allow to configure max_connections_per_node
FranGM May 2, 2021
972f82d
Update to current redis-py-cluster version
FranGM May 18, 2021
96054f4
Update requirements-transitive.txt
FranGM May 18, 2021
c35f976
Add hot key tracking to docs
May 19, 2021
44ecda5
Update setup.py
FranGM May 19, 2021
99b4ffd
Update docs/api/baseplate/clients/redis_cluster.rst
spladug May 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions baseplate/clients/redis_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ class ClusterWithReadReplicasBlockingConnectionPool(rediscluster.ClusterBlocking
def get_node_by_slot(self, slot: int, read_command: bool = False) -> Dict[str, Any]:
"""
Get a node from the slot.
If the command is a read command we'll try to return a random replica.
If the command is a read command we'll try to return a random node.
If there are no replicas or this isn't a read command we'll return the primary.
"""
primary, *replicas = self.nodes.slots[slot]
if read_command:
return random.choice(self.nodes.slots[slot])

if replicas and read_command:
return random.choice(replicas)

# Either this isn't a read command or there aren't any replicas
return primary
# This isn't a read command, so return the primary
return self.nodes.slots[slot]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this not return all of them rather than just the primary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, and I'm very annoyed at myself for not having added a test for that method. I'll fix it and look at adding a test.



def cluster_pool_from_config(
Expand Down