Package: coredis
corediscoredis is an async redis client with support for redis server, cluster & sentinel.The client API uses the specifications in theRedis command documentationto define the API by using the following conventions:Arguments retain naming from redis as much as possibleOnly optional variadic arguments are mapped to variadic positional or keyword arguments.
When the variable length arguments are not optional (which is almost always the case) the expected argument
is an iterable of typeParametersorMapping.Pure tokens used as flags are mapped to boolean argumentsOne ofarguments accepting pure tokens are collapsed and accept aPureTokenResponses are mapped between RESP and python types as closely as possible.For higher level concepts such as Pipelines, LUA Scripts, PubSub & Streams
abstractions are provided to encapsulate recommended patterns.
See theHandbookand theAPI Documentationfor more details.WarningThe command API does NOT mirror the official pythonredis client. For details about the high level differences refer toDivergence from aredis & redis-pyInstallationFeature SummaryDeployment topologiesApplication patternsServer side scriptingRedis ModulesMiscellaneousQuick startSingle Node or Cluster clientSentinelCompatibilitySupported python versionsRedis-like backendsReferencesInstallationTo install coredis:$pipinstallcoredisFeature SummaryDeployment topologiesRedis ClusterSentinelApplication patternsConnection PoolingPubSubSharded PubSub[>= Redis 7.0]Stream ConsumersPipeliningClient side cachingServer side scriptingLUA ScriptingRedis Libraries and functions[>= Redis 7.0]Redis ModulesRedisJSONRediSearchRedisGraphRedisBloomRedisTimeSeriesMiscellaneousPublic API annotated with type annotationsOptionalRuntime Type Validation(viabeartype)Quick startSingle Node or Cluster clientimportasynciofromcoredisimportRedis,RedisClusterasyncdefexample():client=Redis(host='127.0.0.1',port=6379,db=0)# or with redis cluster# client = RedisCluster(startup_nodes=[{"host": "127.0.01", "port": 7001}])awaitclient.flushdb()awaitclient.set('foo',1)assertawaitclient.exists(['foo'])==1assertawaitclient.incr('foo')==2assertawaitclient.incrby('foo',increment=100)==102assertint(awaitclient.get('foo'))==102assertawaitclient.expire('foo',1)awaitasyncio.sleep(0.1)assertawaitclient.ttl('foo')==1assertawaitclient.pttl('foo')<1000awaitasyncio.sleep(1)assertnotawaitclient.exists(['foo'])asyncio.run(example())Sentinelimportasynciofromcoredis.sentinelimportSentinelasyncdefexample():sentinel=Sentinel(sentinels=[("localhost",26379)])primary=sentinel.primary_for("myservice")replica=sentinel.replica_for("myservice")assertawaitprimary.set("fubar",1)assertint(awaitreplica.get("fubar"))==1asyncio.run(example())To see a full list of supported redis commands refer to theCommand
compatibilitydocumentationDetails about supported Redis modules and their commands can be foundhereCompatibilitycoredis is tested against redis versions6.2.x,7.0.x&7.2.x.
The test matrix status can be reviewedherecoredis is additionally tested against:uvloop >= 0.15.0Supported python versions3.83.93.103.11PyPy 3.8PyPy 3.9Redis-like backendscoredisis known to work with the following databases that have redis protocol compatibility:KeyDBDragonflyReferencesDocumentation (Stable)Documentation (Latest)ChangelogProject History