Package: aioredis-cluster
aioredis_clusterRedis Cluster support foraioredis(support only v1.x.x).Many implementation features were inspired bygo-redisproject.RequirementsPython3.8+async_timeout(only for Python < 3.11)Featurescommands execute failover (retry command on other node in cluster)support resharding replies ASK/MOVEDrestore cluster state from alive nodesone node is enough to know the topology and initialize clientcluster state auto reloadLimitationsCommands with limitationsKeys inmget/msetmust provide one key slot.# worksawaitredis.mget("key1:{foo}","key2:{foo}")# throw RedisClusterErrorawaitredis.mget("key1","key2")Commands are not supportedRedismethods 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_execBut you can always execute command you need on concrete node on cluster with usualaioredis.RedisConnection,aioredis.ConnectionsPoolor high-levelaioredis.Redisinterfaces.Installationpipinstallaioredis-clusterUsageimportaioredis_clusterredis=awaitaioredis_cluster.create_redis_cluster(["redis://redis-cluster-node1",])# orredis=awaitaioredis_cluster.create_redis_cluster(["redis://redis-cluster-node1","redis://redis-cluster-node2","redis://redis-cluster-node3",])# orredis=awaitaioredis_cluster.create_redis_cluster([("redis-cluster-node1",6379),])awaitredis.set("key","value",expire=180)redis.close()awaitredis.wait_closed()LicenseThe aioredis_cluster is offered under MIT license.Changes2.7.0 (2023-12-18)Rework PubSub and fix race conditions (#27)addaioredis_cluster.aioredis.streammodulerework PubSub command execution flow for prevent race conditions on spontaneously server channels unsubscribe pushmake fully dedicatedRedisConnectionimplementation for clusterRedisConnectiononce entered in PubSub mode was never exit in them, because is too hard handle spontaneously unsubscribe events from Redis with simultaneously(P|S)UNSUBSCRIBEmanually callsfully rewrite handling PUB/SUB replies/eventsforCluster,RedisConnectionandConnectionsPoolin_pubsubindicates flag when connector have in pubsub mode connections instead number of PUB/SUB channelsadd key slot handling for sharded PubSub channels in non-cluster dedicateRedisConnectionfix and improve legacyaioredistestsimprove support for py3.12improve support for Redis 7.22.6.0 (2023-11-02)fix stuckaioredis.Connectionsocket reader routine for sharded PUB/SUB when cluster reshard and Redis starts respondMOVEDerror onSSUBSCRIBEcommands#242.5.0 (2023-04-03)improve connection creation timeoutdo not lose connection in Pool while execute PING proberespect Pool.minsize in idle connections detectorshuffle startup nodes for obtain cluster state2.4.0 (2023-03-08)add supportSharded PUB/SUBnew methods and propertiesspublish,ssubscribe,sunsubscribe,pubsub_shardchannels,pubsub_shardnumsub,sharded_pubsub_channelsdrop support Python 3.6, 3.7add support Python 3.11idle connections detection in connections poolchange acquire connection behaviour from connection pool. Now connection acquire and release to pool by LIFO way for better idle connection detectiondeprecatedstate_reload_frequencyoption fromcreate_clusterfactory was removed2.3.1 (2022-07-29)fix bypassusernameargument for pool creation2.3.0 (2022-07-26)add support Redis 6AUTHcommand with usernamefactoriescreate_cluster,create_redis_cluster,aioredis_cluster.aioredis.create_connectionnow supportusernameargumentaddauth_with_usernamemethod forAbcConnection,AbcPooland impementations2.2.2 (2022-07-19)fix problem when RedisConnection was GC collected after unhandledasyncio.CancelledErrorfix defaultdbargument for pool/connection in cluster mode2.2.1 (2022-07-18)(revert) apply cluster state only if cluster metadata is changed2.2.0 (2022-07-18)fetch several cluster state candidates from cluster for choose best metadata for final local stateapply cluster state only if cluster metadata is changedFIX: handle closed pubsub connection before gc its collected that triggerTask was destroyed but it is pending!message in logimprove logging in state loader2.1.0 (2022-07-10)fix bug whenConnectionsPool.acquire()is stuck because closed PUB/SUB connection is not cleanup fromusedsetfixConnectionsPool.acquire()incorrect wakeup order for connection waiters when connection is releasedConnectionsPool.execute()now acquire dedicate connection for execution if command is blocking, ex.BLPOPConnectionsPool.execute()now raisesValueErrorexception for PUB/SUB family commandInConnectionsPoolPUB/SUB dedicated connections now is closing onclose()calladdaioredis_cluster.abc.AbcConnectionabstract classadd propertyreadonlyand methodset_readonly()foraioredis_cluster.abc.AbcConnectionandaioredis_cluster.abc.AbcPoolaioredis_cluster.Clusternow requirepool_clsimplementation fromaioredis_cluster.abc.AbcPooladdsslargument for factoriescreate_cluster,create_redis_clusterandClusterconstructoradd 10% jitter for cluster state auto reload intervalfix incorrect iterate free connections inselect(),auth()methods forConnectionsPool2.0.0 (2022-06-20)includeaioredis==1.3.1source code intoaioredis_cluster._aioredisand introduceaioredis_cluster.aioredisbut for compatible and migration periodthis release have not backward incompatible changesDEPRECATION WARNING:you must migrate fromimport aioredistoimport aioredis_cluster.aioredisbecauseaioredis_clusterstarts vendorizeaioredispackage and maintain it separately. Usingaioredispackagewill be removed in v3fix reacquire connection inaioredic.ConnectionsPoolafter Redis node failure1.8.0 (2022-05-20)Addxadd_620commands method for supportXADDoptions for Redis 6.2+1.7.1 (2021-12-15)addClusterState.slots_assignedrequire reload cluster state for some cases withUncoveredSlotError1.7.0 (2021-12-15)addexecute_timeoutforManagerimprove cluster state reload loggingreduce number of addresses to fetch cluster stateacquire dedicate connection from pool to fetch cluster stateextendClusterStateby new attributes:state,state_from,current_epoch1.6.1 (2021-11-23)fix keys extraction forXREADandXREADGROUPcommands1.6.0 (2021-11-20)make publicAddress,ClusterNodeandClusterStatestructs. Available by importfrom aioredis_cluster importClusterprovides 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 sequencedroppytest-aiohttpplugin for testsaddpytest-asynciodependency for testsswitchasynctest->mocklibrary for aio testsdropattrsdependency. For Python 3.6 you need installdataclassesfix extract keys forBLPOP/BRPOPcommandsadd support keys extraction forZUNION,ZINTER,ZDIFF,ZUNIONSTORE,ZINTERSTORE,ZDIFFSTOREcommandsacquire dedicate connection from pool for potential blocking commands likeBLPOP,BRPOP,BRPOPLPUSH,BLMOVE,BLMPOP,BZPOPMIN,BZPOPMAX,XREAD,XREADGROUP1.5.2 (2020-12-14)README update1.5.1 (2020-12-11)speedup crc16. Use implementation from python stdlib1.5.0 (2020-12-10)removestate_reload_frequencyfromClusterManager.state_reload_intervalnow is one relevant option for state auto reloaddefaultstate_reload_intervalincreased and now is 300 seconds (5 minutes)commands registry loads only once, on cluster state initializeimprove failover. First connection problem cause retry to random slot replicaimprove python3.9 supportdefaultidle_connection_timeoutnow is 10 minutes1.4.0 (2020-09-08)fixaioredis.locks.Lockissue (https://github.com/aio-libs/aioredis/pull/802,bpo32734)nowaioredis_cluster.Clusterdo not acquire dedicate connection for every executeaioredis_clusternow requirespython>=3.6.51.3.0 (2019-10-23)improve compatible with Python 3.8improve failover logic while command timed outread-only commands now retries if attempt_timeout is reachedadd required dependenyasync_timeoutaioredisdependency bound now isaioredis >=1.1.0, <2.0.01.2.0 (2019-09-10)add timeout for command execution (per execution try)add Cluster optionattempt_timeoutfor configure command execution timeout, default timeout is 5 secondsCluster.execute_pubsub() fixes1.1.1 (2019-06-07)CHANGES fix1.1.0 (2019-06-06)Cluster state auto reloadnewstate_reload_frequencyoption to configure state reload frequencynewstate_reload_intervaloption to configure state auto reload intervalfollow_clusteroption enable load cluster state from previous cluster state nodesestablish connection only for master nodes after cluster state loadchange default commands_factory to aioredis_cluster.RedisCluster instead aioredis.Redisall cluster info commands always returns structs with str, not byteskeys_masterandall_mastersmethods now try to ensure cluster state instead simply raise exception if connection lost to cluster node, for examplemax_attemptsalways defaults fix1.0.0 (2019-05-29)Library full rewriteCluster state auto reloadCommand failover if cluster node is down or key slot resharded0.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+ only0.1.0 (2018-12-24)Initial release based on aioredis PR (https://github.com/aio-libs/aioredis/pull/119)ContributorsAnton IlyushenkovVadim Pushtaeverastovroman901Alexander Malev