Skip to main content

Python async client for Redis key-value store

Project description

coredis

docs codecov Latest Version in PyPI ci Supported Python versions

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

Installation

To install coredis:

$ pip install coredis

Feature Summary

Deployment topologies

Application patterns

Server side scripting

Miscellaneous

Quick start

Single Node client

import asyncio
from coredis import Redis

async def example():
    client = Redis(host='127.0.0.1', port=6379, db=0)
    await client.flushdb()
    await client.set('foo', 1)
    assert await client.exists(['foo']) == 1
    await client.incr('foo')
    await client.incrby('foo', increment=100)

    assert int(await client.get('foo')) == 102
    await client.expire('foo', 1)
    await asyncio.sleep(0.1)
    await client.ttl('foo')
    await asyncio.sleep(1)
    assert not await client.exists(['foo'])

asyncio.run(example())

Cluster client

import asyncio
from coredis import RedisCluster

async def example():
    client = RedisCluster(host='172.17.0.2', port=7001)
    await client.flushdb()
    await client.set('foo', 1)
    await client.lpush('a', [1])
    print(await client.cluster_slots())

    await client.rpoplpush('a', 'b')
    assert await client.rpop('b') == b'1'

asyncio.run(example())
# {(10923, 16383): [{'host': b'172.17.0.2', 'node_id': b'332f41962b33fa44bbc5e88f205e71276a9d64f4', 'server_type': 'master', 'port': 7002},
# {'host': b'172.17.0.2', 'node_id': b'c02deb8726cdd412d956f0b9464a88812ef34f03', 'server_type': 'slave', 'port': 7005}],
# (5461, 10922): [{'host': b'172.17.0.2', 'node_id': b'3d1b020fc46bf7cb2ffc36e10e7d7befca7c5533', 'server_type': 'master', 'port': 7001},
# {'host': b'172.17.0.2', 'node_id': b'aac4799b65ff35d8dd2ad152a5515d15c0dc8ab7', 'server_type': 'slave', 'port': 7004}],
# (0, 5460): [{'host': b'172.17.0.2', 'node_id': b'0932215036dc0d908cf662fdfca4d3614f221b01', 'server_type': 'master', 'port': 7000},
# {'host': b'172.17.0.2', 'node_id': b'f6603ab4cb77e672de23a6361ec165f3a1a2bb42', 'server_type': 'slave', 'port': 7003}]}

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

Compatibility

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

coredis is additionally tested against:

  • hiredis >= 2.0.0
  • uvloop >= 0.15.0

hiredis if available will be used by default as the RESP (or RESP3) parser as it provides significant performance gains in response parsing. For more details refer to the the documentation section on Parsers

Supported python versions

  • 3.8
  • 3.9
  • 3.10

Experimental Backends

coredis has experimental support for the following redis compatible backends:

References

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

coredis-3.8.12.tar.gz (177.9 kB view hashes)

Uploaded Source

Built Distributions

coredis-3.8.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (384.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

coredis-3.8.12-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (236.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

coredis-3.8.12-cp311-cp311-macosx_10_9_x86_64.whl (299.3 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

coredis-3.8.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (387.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

coredis-3.8.12-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (388.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

coredis-3.8.12-cp310-cp310-macosx_10_9_x86_64.whl (301.5 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

coredis-3.8.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (386.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

coredis-3.8.12-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (386.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

coredis-3.8.12-cp39-cp39-macosx_10_9_x86_64.whl (301.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

coredis-3.8.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (382.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

coredis-3.8.12-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (382.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

coredis-3.8.12-cp38-cp38-macosx_10_9_x86_64.whl (299.8 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page