Redis Cluster support extension for aioredis
Project description
aioredis_cluster
Redis Cluster support for aioredis (support only v1.x.x).
Many implementation features were inspired by go-redis project.
Requirements
- Python 3.8+
- async_timeout (only for Python < 3.11)
Features
- commands execute failover (retry command on other node in cluster)
- support resharding replies ASK/MOVED
- restore cluster state from alive nodes
- one node is enough to know the topology and initialize client
- cluster state auto reload
Limitations
Commands with limitations
- Keys in
mget/msetmust provide one key slot.# works await redis.mget("key1:{foo}", "key2:{foo}") # throw RedisClusterError await redis.mget("key1", "key2")
Commands are not supported
Redis methods below do not works and not supported in cluster mode implementation.
cluster_add_slots
cluster_count_failure_reports
cluster_count_key_in_slots
cluster_del_slots
cluster_failover
cluster_forget
cluster_get_keys_in_slots
cluster_meet
cluster_replicate
cluster_reset
cluster_save_config
cluster_set_config_epoch
cluster_setslot
cluster_readonly
cluster_readwrite
client_setname
shutdown
slaveof
script_kill
move
select
flushall
flushdb
script_load
script_flush
script_exists
scan
iscan
quit
swapdb
migrate
migrate_keys
wait
bgrewriteaof
bgsave
config_rewrite
config_set
config_resetstat
save
sync
pipeline
multi_exec
But you can always execute command you need on concrete node on cluster with usual aioredis.RedisConnection, aioredis.ConnectionsPool or high-level aioredis.Redis interfaces.
Installation
pip install aioredis-cluster
Usage
import aioredis_cluster
redis = await aioredis_cluster.create_redis_cluster([
"redis://redis-cluster-node1",
])
# or
redis = await aioredis_cluster.create_redis_cluster([
"redis://redis-cluster-node1",
"redis://redis-cluster-node2",
"redis://redis-cluster-node3",
])
# or
redis = await aioredis_cluster.create_redis_cluster([
("redis-cluster-node1", 6379),
])
await redis.set("key", "value", expire=180)
redis.close()
await redis.wait_closed()
License
The aioredis_cluster is offered under MIT license.
Changes
2.7.0 (2023-12-18)
Rework PubSub and fix race conditions (#27)
- add
aioredis_cluster.aioredis.streammodule - rework PubSub command execution flow for prevent race conditions on spontaneously server channels unsubscribe push
- make fully dedicated
RedisConnectionimplementation for cluster RedisConnectiononce entered in PubSub mode was never exit in them, because is too hard handle spontaneously unsubscribe events from Redis with simultaneously(P|S)UNSUBSCRIBEmanually calls- fully rewrite handling PUB/SUB replies/events
- for
Cluster,RedisConnectionandConnectionsPoolin_pubsubindicates flag when connector have in pubsub mode connections instead number of PUB/SUB channels - add key slot handling for sharded PubSub channels in non-cluster dedicate
RedisConnection - fix and improve legacy
aioredistests - improve support for py3.12
- improve support for Redis 7.2
2.6.0 (2023-11-02)
- fix stuck
aioredis.Connectionsocket reader routine for sharded PUB/SUB when cluster reshard and Redis starts respondMOVEDerror onSSUBSCRIBEcommands #24
2.5.0 (2023-04-03)
- improve connection creation timeout
- do not lose connection in Pool while execute PING probe
- respect Pool.minsize in idle connections detector
- shuffle startup nodes for obtain cluster state
2.4.0 (2023-03-08)
- add support Sharded PUB/SUB
- new methods and properties
spublish,ssubscribe,sunsubscribe,pubsub_shardchannels,pubsub_shardnumsub,sharded_pubsub_channels - drop support Python 3.6, 3.7
- add support Python 3.11
- idle connections detection in connections pool
- change acquire connection behaviour from connection pool. Now connection acquire and release to pool by LIFO way for better idle connection detection
- deprecated
state_reload_frequencyoption fromcreate_clusterfactory was removed
2.3.1 (2022-07-29)
- fix bypass
usernameargument for pool creation
2.3.0 (2022-07-26)
- add support Redis 6
AUTHcommand with username - factories
create_cluster,create_redis_cluster,aioredis_cluster.aioredis.create_connectionnow supportusernameargument - add
auth_with_usernamemethod forAbcConnection,AbcPooland impementations
2.2.2 (2022-07-19)
- fix problem when RedisConnection was GC collected after unhandled
asyncio.CancelledError - fix default
dbargument for pool/connection in cluster mode
2.2.1 (2022-07-18)
- (revert) apply cluster state only if cluster metadata is changed
2.2.0 (2022-07-18)
- fetch several cluster state candidates from cluster for choose best metadata for final local state
- apply cluster state only if cluster metadata is changed
- FIX: handle closed pubsub connection before gc its collected that trigger
Task was destroyed but it is pending!message in log - improve logging in state loader
2.1.0 (2022-07-10)
- fix bug when
ConnectionsPool.acquire()is stuck because closed PUB/SUB connection is not cleanup fromusedset - fix
ConnectionsPool.acquire()incorrect wakeup order for connection waiters when connection is released ConnectionsPool.execute()now acquire dedicate connection for execution if command is blocking, ex.BLPOPConnectionsPool.execute()now raisesValueErrorexception for PUB/SUB family command- In
ConnectionsPoolPUB/SUB dedicated connections now is closing onclose()call - add
aioredis_cluster.abc.AbcConnectionabstract class - add property
readonlyand methodset_readonly()foraioredis_cluster.abc.AbcConnectionandaioredis_cluster.abc.AbcPool aioredis_cluster.Clusternow requirepool_clsimplementation fromaioredis_cluster.abc.AbcPool- add
sslargument for factoriescreate_cluster,create_redis_clusterandClusterconstructor - add 10% jitter for cluster state auto reload interval
- fix incorrect iterate free connections in
select(),auth()methods forConnectionsPool
2.0.0 (2022-06-20)
- include
aioredis==1.3.1source code intoaioredis_cluster._aioredisand introduceaioredis_cluster.aioredisbut for compatible and migration period - this release have not backward incompatible changes
- DEPRECATION WARNING: you must migrate from
import aioredistoimport aioredis_cluster.aioredisbecauseaioredis_clusterstarts vendorizeaioredispackage and maintain it separately. Usingaioredispackage will be removed in v3 - fix reacquire connection in
aioredic.ConnectionsPoolafter Redis node failure
1.8.0 (2022-05-20)
- Add
xadd_620commands method for supportXADDoptions for Redis 6.2+
1.7.1 (2021-12-15)
- add
ClusterState.slots_assigned - require reload cluster state for some cases with
UncoveredSlotError
1.7.0 (2021-12-15)
- add
execute_timeoutforManager - improve cluster state reload logging
- reduce number of addresses to fetch cluster state
- acquire dedicate connection from pool to fetch cluster state
- extend
ClusterStateby new attributes:state,state_from,current_epoch
1.6.1 (2021-11-23)
- fix keys extraction for
XREADandXREADGROUPcommands
1.6.0 (2021-11-20)
- make public
Address,ClusterNodeandClusterStatestructs. Available by importfrom aioredis_cluster import Clusterprovides some new helpful methods:get_master_node_by_keys(*keys)- return masterClusterNodewhich contains keyskeyscreate_pool_by_addr(addr, **kwargs)- create connection pool byaddrand return pool wrapped bycommands_factoryfromClusterconstructor. By default isaioredis_cluster.RedisClusterinstance.get_cluster_state()- returnClusterStateinstance with recent known cluster state received from Redis clusterextract_keys(command_sequence)- returns keys of command sequence
- drop
pytest-aiohttpplugin for tests - add
pytest-asynciodependency for tests - switch
asynctest->mocklibrary for aio tests - drop
attrsdependency. For Python 3.6 you need installdataclasses - fix extract keys for
BLPOP/BRPOPcommands - add support keys extraction for
ZUNION,ZINTER,ZDIFF,ZUNIONSTORE,ZINTERSTORE,ZDIFFSTOREcommands - acquire dedicate connection from pool for potential blocking commands like
BLPOP,BRPOP,BRPOPLPUSH,BLMOVE,BLMPOP,BZPOPMIN,BZPOPMAX,XREAD,XREADGROUP
1.5.2 (2020-12-14)
- README update
1.5.1 (2020-12-11)
- speedup crc16. Use implementation from python stdlib
1.5.0 (2020-12-10)
- remove
state_reload_frequencyfromClusterManager.state_reload_intervalnow is one relevant option for state auto reload - default
state_reload_intervalincreased and now is 300 seconds (5 minutes) - commands registry loads only once, on cluster state initialize
- improve failover. First connection problem cause retry to random slot replica
- improve python3.9 support
- default
idle_connection_timeoutnow is 10 minutes
1.4.0 (2020-09-08)
- fix
aioredis.locks.Lockissue (https://github.com/aio-libs/aioredis/pull/802, bpo32734) - now
aioredis_cluster.Clusterdo not acquire dedicate connection for every execute aioredis_clusternow requirespython>=3.6.5
1.3.0 (2019-10-23)
- improve compatible with Python 3.8
- improve failover logic while command timed out
- read-only commands now retries if attempt_timeout is reached
- add required dependeny
async_timeout aioredisdependency bound now isaioredis >=1.1.0, <2.0.0
1.2.0 (2019-09-10)
- add timeout for command execution (per execution try)
- add Cluster option
attempt_timeoutfor configure command execution timeout, default timeout is 5 seconds - Cluster.execute_pubsub() fixes
1.1.1 (2019-06-07)
- CHANGES fix
1.1.0 (2019-06-06)
- Cluster state auto reload
- new
state_reload_frequencyoption to configure state reload frequency - new
state_reload_intervaloption to configure state auto reload interval follow_clusteroption enable load cluster state from previous cluster state nodes- establish connection only for master nodes after cluster state load
- change default commands_factory to aioredis_cluster.RedisCluster instead aioredis.Redis
- all cluster info commands always returns structs with str, not bytes
keys_masterandall_mastersmethods now try to ensure cluster state instead simply raise exception if connection lost to cluster node, for examplemax_attemptsalways defaults fix
1.0.0 (2019-05-29)
- Library full rewrite
- Cluster state auto reload
- Command failover if cluster node is down or key slot resharded
0.2.0 (2018-12-27)
- Pipeline and MULTI/EXEC cluster implementation with keys distribution limitation (because cluster)
0.1.1 (2018-12-26)
- Python 3.6+ only
0.1.0 (2018-12-24)
- Initial release based on aioredis PR (https://github.com/aio-libs/aioredis/pull/119)
Contributors
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aioredis-cluster-2.7.0.tar.gz.
File metadata
- Download URL: aioredis-cluster-2.7.0.tar.gz
- Upload date:
- Size: 169.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b1bf8e9c8186d2e68a032d8693a8a35b1141a9570db9b8179ef144a318f6dad
|
|
| MD5 |
33352a49f745a73a53b5c6209592836d
|
|
| BLAKE2b-256 |
a53f4d6e03480718265bff20ab343b16fe01b366697a422bda850a4b8d50b0c4
|
File details
Details for the file aioredis_cluster-2.7.0-py3-none-any.whl.
File metadata
- Download URL: aioredis_cluster-2.7.0-py3-none-any.whl
- Upload date:
- Size: 120.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a0b807e337fda9dcdfac22b4fee9b16a41b47a8b22a8358f68524de8827e925
|
|
| MD5 |
d5e242d4595969dd4478e5c4c651ae84
|
|
| BLAKE2b-256 |
319808f0ec788a4d7ce125d5325e1fe5429abcb0106e9529ec7c8f0546776ce9
|