Home

Awesome

coredis

docs codecov Latest Version in PyPI ci Supported Python versions


coredis is an async redis client with support for redis server, cluster & sentinel.

Warning The command API does NOT mirror the official python redis client. For details about the high level differences refer to Divergence from aredis & redis-py


<!-- TOC depthFrom:2 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 --> <!-- /TOC -->

Installation

To install coredis:

$ pip install coredis

Feature Summary

Deployment topologies

Application patterns

Server side scripting

Redis Modules

Miscellaneous

Quick start

Single Node or Cluster client

import asyncio
from coredis import Redis, RedisCluster

async def example():
    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}])
    await client.flushdb()
    await client.set('foo', 1)
    assert await client.exists(['foo']) == 1
    assert await client.incr('foo') == 2
    assert await client.incrby('foo', increment=100) == 102
    assert int(await client.get('foo')) == 102

    assert await client.expire('foo', 1)
    await asyncio.sleep(0.1)
    assert await client.ttl('foo') == 1
    assert await client.pttl('foo') < 1000
    await asyncio.sleep(1)
    assert not await client.exists(['foo'])

asyncio.run(example())

Sentinel

import asyncio
from coredis.sentinel import Sentinel

async def example():
    sentinel = Sentinel(sentinels=[("localhost", 26379)])
    primary = sentinel.primary_for("myservice")
    replica = sentinel.replica_for("myservice")

    assert await primary.set("fubar", 1)
    assert int(await replica.get("fubar")) == 1

asyncio.run(example())

To see a full list of supported redis commands refer to the Command compatibility documentation

Details about supported Redis modules and their commands can be found here

Compatibility

coredis is tested against redis versions 6.2.x, 7.0.x & 7.2.x. The test matrix status can be reviewed here

coredis is additionally tested against:

Supported python versions

Redis-like backends

coredis is known to work with the following databases that have redis protocol compatibility:

References