Skip to content

alisaifee/coredis

Repository files navigation

docs codecov Latest Version in PyPI ci Supported Python versions

Important

The master branch contains the coredis 6.x codebase which is not backward compatible with 5.x. If you are looking for the 5.x implementation, please refer to the 5.x branch.

coredis

Fast, async, fully-typed Redis client with support for cluster and sentinel

Features

Installation

$ pip install coredis

Getting started

To start, you'll need to connect to your Redis instance:

import trio
from coredis import Redis

client = Redis(host='127.0.0.1', port=6379, db=0, decode_responses=True)
async with client:
    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') or 0) == 102

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

Sentinel is also supported:

from coredis.sentinel import Sentinel

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

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

Compatibility

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.

coredis is tested against redis versions >= 7.0 The test matrix status can be reviewed here

coredis is additionally tested against:

  • uvloop >= 0.15.0
  • trio

Supported python versions

  • 3.10
  • 3.11
  • 3.12
  • 3.13
  • PyPy 3.10

Redis API compatible databases

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

References

About

coredis is an async redis client for python with support for redis cluster, sentinel and popular redis modules

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors 35

Languages