Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
8c6dfa1
Combine commits for anyio upgrade
Graeme22 Aug 5, 2025
0c1d856
Merge branch 'master' into anyio
Graeme22 Sep 26, 2025
4d2d563
make tests necessary again
Graeme22 Sep 26, 2025
6bc2b9d
Merge branch 'master' into anyio
Graeme22 Sep 26, 2025
c618d0e
fix blocking command bug
Graeme22 Sep 27, 2025
daeb683
sync w/ master
Graeme22 Oct 11, 2025
b98bb2c
use anyio TLS wrapper
Graeme22 Oct 14, 2025
97657aa
improve blocking pool
Graeme22 Oct 22, 2025
bbf66e6
blocking logic tweak
Graeme22 Oct 27, 2025
d92800c
Add implicit pytest_mode marker for all tests
alisaifee Oct 27, 2025
01483d0
Sync all test fixtures to use async with before yielding client
alisaifee Oct 27, 2025
2fde017
Fix typing ambiguity
alisaifee Oct 28, 2025
5ccd9b3
Merge pull request #3 from alisaifee/anyio
Graeme22 Oct 29, 2025
d20e432
uncouple pool & cxn, restructure pool
Graeme22 Oct 30, 2025
dfc91f9
fix corrupted pubsub issue
Graeme22 Oct 30, 2025
9966498
pubsub reconnection logic
Graeme22 Oct 31, 2025
b7db708
Allow gather to return exceptions
alisaifee Oct 29, 2025
227e5d5
Add utility AsyncQueue
alisaifee Oct 29, 2025
7103ffe
Refactor cluster client/connection pool for anyio
alisaifee Oct 29, 2025
ce67ba9
Simplify implementation of gather
alisaifee Oct 31, 2025
1c2eb64
Ensure per request encoding is respected
alisaifee Nov 1, 2025
215cc57
Ensure noreply commands do not enqueue requests to be parsed
alisaifee Nov 1, 2025
885c999
uncouple pool & cxn, restructure pool
Graeme22 Oct 30, 2025
fd96d9a
fix pool logic
Graeme22 Nov 3, 2025
b0642a1
use deque for free connections, cleaner pubsub cleanup
Graeme22 Nov 4, 2025
754feac
Merge remote-tracking branch 'graeme/anyio' into anyio
alisaifee Nov 4, 2025
74a557b
Change cluster pool internals o LIFO and remove non blocking
alisaifee Nov 4, 2025
c63b462
Remove unused cluster pool disconnect method
alisaifee Nov 4, 2025
591563d
Restore cluster connection pool get_connection public scope
alisaifee Nov 4, 2025
ea0dfcc
Non functional cleanups in cluster pool
alisaifee Nov 4, 2025
23ff1f8
Remove references to blocking fixtures
alisaifee Nov 4, 2025
dbc2a43
Narrow definition of async queue for connections
alisaifee Nov 5, 2025
5dbea9f
Fix incorrectly wrapped pipeline response
alisaifee Nov 5, 2025
680c367
Fix incorrect construction of basic redis fixture
alisaifee Nov 5, 2025
0ad1b98
Fix cluster command tests to correctly use node clients
alisaifee Nov 5, 2025
91cdf6e
Fix server command tests to correctly user cloner
alisaifee Nov 5, 2025
2bdd022
Fix incorrect use of acquire method in generic command tests
alisaifee Nov 5, 2025
b35373a
Fix connection command tests
alisaifee Nov 5, 2025
2e83648
Simplify basic connection pool to use ConnectionQueue
alisaifee Nov 5, 2025
7c9c021
Improve connection error handling
alisaifee Nov 5, 2025
453d29f
Update stream tests to use anyio task group instead of threads
alisaifee Nov 6, 2025
3df2a05
Disable object idle time test for redict
alisaifee Nov 6, 2025
a4ca602
axe multiplexing, re-add transaction/watch helper
Graeme22 Nov 6, 2025
3c2aeb1
remove separate fn for blocking commands
Graeme22 Nov 6, 2025
f0e1dc3
Remove unused cluster in use connection tracking
alisaifee Nov 7, 2025
1b423ff
Reintroduce connection.disconnect method
alisaifee Nov 7, 2025
5ca950b
Add implementation for cluster pubsub
alisaifee Nov 7, 2025
b6d3d4b
Fix parser tests
alisaifee Nov 7, 2025
a0efa78
Fix cluster scan_iter method
alisaifee Nov 7, 2025
37a744d
Ensure cluster pipeline transaction response is awaitable
alisaifee Nov 7, 2025
06ef8dc
Update module tests to use correct pipeline syntax
alisaifee Nov 7, 2025
15f510b
Merge branch 'anyio' into anyio
Graeme22 Nov 7, 2025
156244d
remove disconnect fn and problematic raise
Graeme22 Nov 7, 2025
f5bed44
rename max_block_time
Graeme22 Nov 7, 2025
5caf99a
Merge pull request #6 from alisaifee/anyio
Graeme22 Nov 7, 2025
121fda8
tracking cache migration
Graeme22 Dec 28, 2025
e773665
update cache tests
Graeme22 Dec 28, 2025
6c7dd02
Merge branch 'master' into anyio
Graeme22 Dec 28, 2025
2324c24
lints, sentinel tests
Graeme22 Dec 29, 2025
5896311
reorganize cache
Graeme22 Dec 30, 2025
790c7c5
periodic cache compaction
Graeme22 Dec 30, 2025
b6027f8
docs updates, script wraps improvements
Graeme22 Dec 31, 2025
71c1d46
fix beartype warning
Graeme22 Dec 31, 2025
8073d35
README and docs refresh
Graeme22 Dec 31, 2025
817a3eb
Remove invalid / unnecessary classifiers
alisaifee Jan 5, 2026
833cd87
Remove incorrect kwarg for tracking cache
alisaifee Jan 5, 2026
63b57e9
Remove calls to removed cache.shutdown method
alisaifee Jan 5, 2026
1934e7c
Only initialize cache if provided as kwarg
alisaifee Jan 6, 2026
5524c45
Fix cluster cache initialization
alisaifee Jan 6, 2026
6eadebd
Attempt at implement tracking cache for cluster
alisaifee Jan 7, 2026
95da431
fix mypyc error
Graeme22 Jan 7, 2026
3340075
fix lints
Graeme22 Jan 7, 2026
8dc0f71
move gather out of compiled utils class
Graeme22 Jan 7, 2026
37a24f6
Fix fixture initialization for encoding tests
alisaifee Jan 8, 2026
ff1db51
Fix sentinel tests to work with anyio implementation
alisaifee Jan 9, 2026
bb85816
Move coredis.concurrency -> _concurrency
alisaifee Jan 9, 2026
f41dc9a
Reduce duplication in tracking cache implementation
alisaifee Jan 9, 2026
a4d1093
Remove redundant call to initialize connection pool
alisaifee Jan 9, 2026
984aafe
Fix flaky issues in tracking cache tests
alisaifee Jan 9, 2026
ec9bd7f
Ensure cluster pubsub implementation is in sync with basic pubsub
alisaifee Jan 9, 2026
76716e6
Merge remote-tracking branch 'origin/master' into anyio
alisaifee Jan 9, 2026
6561936
Fix connection tests
alisaifee Jan 9, 2026
1b8b959
remove bytes as size limit in cache, tests update
Graeme22 Jan 11, 2026
010606e
fix lint
Graeme22 Jan 11, 2026
2370f77
fix function tests
Graeme22 Jan 11, 2026
c9eac97
add raises_in_group utility
Graeme22 Jan 11, 2026
807cd66
Add uvloop & orjson to pyproject dev deps
alisaifee Jan 10, 2026
91c819b
Select anyio backend in tests from env var
alisaifee Jan 10, 2026
8afb9d5
Remove outdated connection pool tests
alisaifee Jan 10, 2026
bf33cd0
Only install uvloop for ! PyPy
alisaifee Jan 11, 2026
03640fd
Enforce 30s timeout per test in CI
alisaifee Jan 12, 2026
f410fb8
Increase CI timeout to 60s
alisaifee Jan 12, 2026
8b94361
use pytest RaisesGroup, catch BrokenResourceError
Graeme22 Jan 12, 2026
744868a
undo connection changes
Graeme22 Jan 12, 2026
3d3bf22
fix a few tests related to exception groups
Graeme22 Jan 12, 2026
9adddc5
Improve cluster pipeline error handling and api compatibility
alisaifee Jan 12, 2026
4a89053
raise prior to cxn established, not after
Graeme22 Jan 12, 2026
ea6aac5
Merge remote-tracking branch 'upstream/anyio' into anyio
Graeme22 Jan 12, 2026
ec28591
Improve cluster pipeline error handling and api compatibility
alisaifee Jan 12, 2026
0eb7e4b
Do not return broken connections to the pool
alisaifee Jan 12, 2026
2d41a4d
remove unused vars
Graeme22 Jan 12, 2026
e702021
Merge remote-tracking branch 'upstream/anyio' into anyio
Graeme22 Jan 12, 2026
05809ba
fix lint
Graeme22 Jan 12, 2026
edd287c
add debug info
Graeme22 Jan 12, 2026
ac7dc87
Fix incorrect handling of uvloop env var for tests
alisaifee Jan 12, 2026
27f9c9c
Improve stability of pipeline timeout tests
alisaifee Jan 12, 2026
d624ea0
Merge remote-tracking branch 'upstream/anyio' into anyio
Graeme22 Jan 12, 2026
26299fd
add back server side
Graeme22 Jan 12, 2026
4657343
retry on cxn failure
Graeme22 Jan 12, 2026
571cb8c
Drop RESP2 support
alisaifee Jan 12, 2026
3aefc3a
fix flaky test
Graeme22 Jan 13, 2026
0116969
Merge remote-tracking branch 'upstream/anyio' into anyio
Graeme22 Jan 13, 2026
cc0c73a
Merge branch 'master' into anyio
Graeme22 Jan 13, 2026
811b4df
fix lint
Graeme22 Jan 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
exit 1
fi;
test:
name: Test (Python ${{ matrix.python-version }}, Redis ${{ matrix.redis-version }}${{ matrix.uvloop == 'True' && ', uvloop' || ''}}${{ matrix.orjson == 'True' && ', orjson' || ''}}${{ matrix.extensions == 'True' && ', compiled' || ''}}${{ matrix.label && format(', {0}', matrix.label) || '' }})
name: Test (Python ${{ matrix.python-version }}, Anyio ${{ matrix.anyio-backend || 'asyncio' }}, Redis ${{ matrix.redis-version }}${{ matrix.uvloop == 'True' && ', uvloop' || ''}}${{ matrix.orjson == 'True' && ', orjson' || ''}}${{ matrix.extensions == 'True' && ', compiled' || ''}}${{ matrix.label && format(', {0}', matrix.label) || '' }})
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.redis-version == 'next' }}
strategy:
Expand All @@ -52,6 +52,7 @@ jobs:
test_params: ["-m '(not (dragonfly or valkey or redict))'"]
orjson: ["False"]
uvloop: ["False"]
anyio-backend: ["asyncio"]
runtime_type_checks: ["True"]
extensions: ["True"]
label: [""]
Expand All @@ -72,6 +73,12 @@ jobs:
extensions: "False"
runtime_type_checks: "True"
label: ""
- python-version: "3.13"
redis-version: latest
test_params: "-m '(not (dragonfly or valkey or redict))'"
runtime_type_checks: "True"
anyio-backend: "trio"
label: ""
- python-version: "3.13"
redis-version: latest
test_params: "-m '(not (dragonfly or valkey or redict))'"
Expand Down Expand Up @@ -126,28 +133,22 @@ jobs:
- name: Compile extensions
if: ${{ matrix.extensions == 'True' }}
run: uv run mypyc coredis/constants.py coredis/parser.py coredis/_packer.py coredis/_utils.py
- name: Install uvloop
if: ${{ matrix.uvloop == 'True' }}
run:
uv pip install uvloop
- name: Install orjson
if: ${{ matrix.orjson == 'True' }}
run:
uv pip install orjson
- name: Tests with coverage
env:
COREDIS_UVLOOP: ${{ matrix.uvloop }}
COREDIS_ANYIO_BACKEND: ${{ matrix.anyio-backend }}
HOST_OS: linux
CI: "True"
COREDIS_REDIS_VERSION: ${{matrix.redis-version}}
COREDIS_RUNTIME_CHECKS: ${{matrix.runtime_type_checks}}
PYTEST_SENTRY_DSN: ${{ matrix.extensions != 'True' && secrets.SENTRY_DSN || ''}}
COMPOSE_PARALLEL_LIMIT: 1
UV_GROUP: ${{ matrix.orjson == 'True' && 'orjson' || 'dev' }}
run: |
echo "Runtime checks: $COREDIS_RUNTIME_CHECKS"
echo "UVLoop: $COREDIS_UVLOOP"
echo "CI: $CI"
uv run pytest --reverse --reruns 2 --cov=coredis --cov-report=xml ${{ matrix.test_params }}
uv run --group $UV_GROUP pytest --timeout=60 --reverse --reruns 2 --cov=coredis --cov-report=xml ${{ matrix.test_params }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.2.0
env:
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
exit 1
fi;
test:
name: Test (Python ${{ matrix.python-version }}, Redis ${{ matrix.redis-version }}${{ matrix.uvloop == 'True' && ', uvloop' || ''}}${{ matrix.orjson == 'True' && ', orjson' || ''}}${{ matrix.extensions == 'True' && ', compiled' || ''}}${{ matrix.label && format(', {0}', matrix.label) || '' }})
name: Test (Python ${{ matrix.python-version }}, ${{ matrix.anyio-backend || 'asyncio' }}, Redis ${{ matrix.redis-version }}${{ matrix.uvloop == 'True' && ', uvloop' || ''}}${{ matrix.orjson == 'True' && ', orjson' || ''}}${{ matrix.extensions == 'True' && ', compiled' || ''}}${{ matrix.label && format(', {0}', matrix.label) || '' }})
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.redis-version == 'next' }}
strategy:
Expand All @@ -47,6 +47,7 @@ jobs:
test_params: ["-m '(not (dragonfly or valkey or redict))'"]
uvloop: ["False"]
orjson: ["False"]
anyio-backend: ["asyncio"]
runtime_type_checks: ["True"]
extensions: ["True"]
label: [""]
Expand All @@ -66,6 +67,11 @@ jobs:
test_params: "-m '(not (dragonfly or valkey or redict))'"
runtime_type_checks: "True"
uvloop: "True"
- python-version: "3.13"
redis-version: "latest"
test_params: "-m '(not (dragonfly or valkey or redict))'"
runtime_type_checks: "True"
anyio-backend: "trio"
- python-version: "3.13"
redis-version: "latest"
test_params: "-m dragonfly"
Expand Down Expand Up @@ -102,28 +108,22 @@ jobs:
- name: Compile extensions
if: ${{ matrix.extensions == 'True' }}
run: uv run mypyc coredis/constants.py coredis/parser.py coredis/_packer.py coredis/_utils.py
- name: Install uvloop
if: ${{ matrix.uvloop == 'True' }}
run:
uv pip install uvloop
- name: Install orjson
if: ${{ matrix.orjson == 'True' }}
run:
uv pip install orjson
- name: Tests
env:
COREDIS_UVLOOP: ${{ matrix.uvloop }}
COREDIS_ANYIO_BACKEND: ${{ matrix.anyio-backend }}
HOST_OS: linux
CI: "True"
COREDIS_REDIS_VERSION: ${{matrix.redis-version}}
COREDIS_RUNTIME_CHECKS: ${{matrix.runtime_type_checks}}
PYTEST_SENTRY_DSN: ${{ matrix.extensions != 'True' && secrets.SENTRY_DSN || ''}}
COMPOSE_PARALLEL_LIMIT: 1
UV_GROUP: ${{ matrix.orjson == 'True' && 'orjson' || 'dev' }}
run: |
echo "Runtime checks: $COREDIS_RUNTIME_CHECKS"
echo "UVLoop: $COREDIS_UVLOOP"
echo "CI: $CI"
uv run pytest --reverse --reruns 2 --cov=coredis --cov-report=xml ${{ matrix.test_params }}
uv run --group $UV_GROUP pytest --timeout=60 --reverse --reruns 2 --cov=coredis --cov-report=xml ${{ matrix.test_params }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.2.0
env:
Expand Down
28 changes: 28 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@
Changelog
=========

v6.0.0rc1
---------
Release Date: TBD

* Feature

* Migrates entire library to ``anyio``, adding structured concurrency and Trio support.

* Almost all objects (clients, connection pools, PubSub, pipelines) now require use of
an async context manager for initialization/cleanup.
* Test suite now runs tests on both asyncio and Trio backends
* Caching is simplified, and users should replace ``TrackingCache`` instances with a
``LRUCache`` instance instead. Cache no longer has a max byte size, so max keys
should be used instead.
* All connection types use ``anyio`` networking APIs.
* ``Pipeline.execute()`` no longer exists. Instead, pipelines auto-execute when leaving
their context manager. Results can be accessed afterwards in a type-safe way.
* RESP2 support has been dropped.
* All connection pools are now blocking.
* ``Library.wraps`` is now just ``wraps`` and supports callbacks. It also optimistically
calls FCALL in pipelines instead of checking the function exists first.
* When defining type stubs for FFI for Lua scripts or library functions, keys can only
be distinguished from arguments by annotating them with the ``KeyT`` type.
* EVALSHA and FCALL commands now support optional callbacks
* Removes ``Monitor`` wrapper
* Client now includes ``Redis.lock`` as a convenient way to access the ``LuaLock``
recipe, and the class is now just called ``Lock``.

v5.5.0
------
Release Date: 2026-01-12
Expand Down
142 changes: 37 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,156 +1,88 @@
# coredis

[![docs](https://readthedocs.org/projects/coredis/badge/?version=stable)](https://coredis.readthedocs.org)
[![codecov](https://codecov.io/gh/alisaifee/coredis/branch/master/graph/badge.svg)](https://codecov.io/gh/alisaifee/coredis)
[![Latest Version in PyPI](https://img.shields.io/pypi/v/coredis.svg)](https://pypi.python.org/pypi/coredis/)
[![ci](https://github.com/alisaifee/coredis/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/alisaifee/coredis/actions?query=branch%3Amaster+workflow%3ACI)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/coredis.svg)](https://pypi.python.org/pypi/coredis/)

______________________________________________________________________

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

- The client API uses the specifications in the [Redis command documentation](https://redis.io/commands/) to define the API by using the following conventions:

- Arguments retain naming from redis as much as possible
- Only 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 type [Parameters](https://coredis.readthedocs.io/en/latest/api/typing.html#coredis.typing.Parameters) or `Mapping`.
- Pure tokens used as flags are mapped to boolean arguments
- `One of` arguments accepting pure tokens are collapsed and accept a [PureToken](https://coredis.readthedocs.io/en/latest/api/utilities.html#coredis.tokens.PureToken)

- Responses 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 the [Handbook](https://coredis.readthedocs.io/en/latest/handbook/index.html)
and the [API Documentation](https://coredis.readthedocs.io/en/latest/api/index.html)
for more details.

______________________________________________________________________
# coredis

<!-- TOC depthFrom:2 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->
Fast, async, fully-typed Redis client with support for cluster and sentinel

- [Installation](#installation)
- [Feature Summary](#feature-summary)
- [Deployment topologies](#deployment-topologies)
- [Application patterns](#application-patterns)
- [Server side scripting](#server-side-scripting)
- [Redis Modules](#redis-modules)
- [Miscellaneous](#miscellaneous)
- [Quick start](#quick-start)
- [Single Node or Cluster client](#single-node-or-cluster-client)
- [Sentinel](#sentinel)
- [Compatibility](#compatibility)
- [Supported python versions](#supported-python-versions)
- [Redis API compatible databases backends](#redis-api-compatible-databases)
- [References](#references)
## Features

<!-- /TOC -->
- Fully typed, even when using pipelines, Lua scripts, and libraries
- Redis [Cluster](https://coredis.readthedocs.org/en/latest/handbook/cluster.html#redis-cluster) and [Sentinel](https://coredis.readthedocs.org/en/latest/api/clients.html#sentinel) support
- Built with structured concurrency on `anyio`, supports both `asyncio` and `trio`
- Server-assisted [client-side caching](https://coredis.readthedocs.org/en/latest/handbook/caching.html) implementation
- [Redis Stack modules](https://coredis.readthedocs.org/en/latest/handbook/modules.html) support
- [Redis PubSub](https://coredis.readthedocs.org/en/latest/handbook/pubsub.html)
- [Pipelining](https://coredis.readthedocs.org/en/latest/handbook/pipelines.html)
- [Lua scripts](https://coredis.readthedocs.org/en/latest/handbook/scripting.html#lua_scripting) and [Redis functions](https://coredis.readthedocs.org/en/latest/handbook/scripting.html#library-functions) \[`>= Redis 7.0`\] support, with optional types
- Convenient [Stream Consumers](https://coredis.readthedocs.org/en/latest/handbook/streams.html) implementation
- Comprehensive documentation
- Optional [runtime type validation](https://coredis.readthedocs.org/en/latest/handbook/typing.html#runtime-type-checking) (via [beartype](https://github.com/beartype/beartype))

## Installation

To install coredis:

```bash
```console
$ pip install coredis
```

## Feature Summary

### Deployment topologies

- [Redis Cluster](https://coredis.readthedocs.org/en/latest/handbook/cluster.html#redis-cluster)
- [Sentinel](https://coredis.readthedocs.org/en/latest/api/clients.html#sentinel)

### Application patterns

- [Connection Pooling](https://coredis.readthedocs.org/en/latest/handbook/connections.html#connection-pools)
- [PubSub](https://coredis.readthedocs.org/en/latest/handbook/pubsub.html)
- [Sharded PubSub](https://coredis.readthedocs.org/en/latest/handbook/pubsub.html#sharded-pub-sub) \[`>= Redis 7.0`\]
- [Stream Consumers](https://coredis.readthedocs.org/en/latest/handbook/streams.html)
- [Pipelining](https://coredis.readthedocs.org/en/latest/handbook/pipelines.html)
- [Client side caching](https://coredis.readthedocs.org/en/latest/handbook/caching.html)

### Server side scripting

- [LUA Scripting](https://coredis.readthedocs.org/en/latest/handbook/scripting.html#lua_scripting)
- [Redis Libraries and functions](https://coredis.readthedocs.org/en/latest/handbook/scripting.html#library-functions) \[`>= Redis 7.0`\]

### Redis Modules

- [RedisJSON](https://coredis.readthedocs.org/en/latest/handbook/modules.html#redisjson)
- [RediSearch](https://coredis.readthedocs.org/en/latest/handbook/modules.html#redisearch)
- [RedisBloom](https://coredis.readthedocs.org/en/latest/handbook/modules.html#redisbloom)
- [RedisTimeSeries](https://coredis.readthedocs.org/en/latest/handbook/modules.html#redistimeseries)

### Miscellaneous

- Public API annotated with type annotations
- Optional [Runtime Type Validation](https://coredis.readthedocs.org/en/latest/handbook/typing.html#runtime-type-checking) (via [beartype](https://github.com/beartype/beartype))

## Quick start
## Getting started

### Single Node or Cluster client
To start, you'll need to connect to your `Redis` instance:

```python
import asyncio
from coredis import Redis, RedisCluster
import trio
from coredis import Redis

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}])
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')) == 102
assert int(await client.get('foo') or 0) == 102

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

asyncio.run(example())
```

### Sentinel
Sentinel is also supported:

```python
import asyncio
from coredis.sentinel import Sentinel

async def example():
sentinel = Sentinel(sentinels=[("localhost", 26379)])
sentinel = Sentinel(sentinels=[("localhost", 26379)])
async with sentinel:
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())
async with primary, replica:
assert await primary.set("fubar", 1)
assert int(await replica.get("fubar")) == 1
```

To see a full list of supported redis commands refer to the [Command
compatibility](https://coredis.readthedocs.io/en/latest/compatibility.html)
documentation

Details about supported Redis modules and their commands can be found
[here](https://coredis.readthedocs.io/en/latest/handbook/modules.html)

## Compatibility

To see a full list of supported Redis commands refer to the [Command
compatibility](https://coredis.readthedocs.io/en/latest/compatibility.html)
documentation. Details about supported Redis modules and their commands can be found
[here](https://coredis.readthedocs.io/en/latest/handbook/modules.html).

coredis is tested against redis versions >= `7.0`
The test matrix status can be reviewed
[here](https://github.com/alisaifee/coredis/actions/workflows/main.yml)

coredis is additionally tested against:

- ` uvloop >= 0.15.0`
- `uvloop >= 0.15.0`
- `trio`

### Supported python versions

Expand Down
11 changes: 3 additions & 8 deletions coredis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
Connection,
UnixDomainSocketConnection,
)
from coredis.pool import (
BlockingClusterConnectionPool,
BlockingConnectionPool,
ClusterConnectionPool,
ConnectionPool,
)
from coredis.pool import ClusterConnectionPool, ConnectionPool
from coredis.sentinel import Sentinel
from coredis.tokens import PureToken

__all__ = [
Expand All @@ -33,10 +29,9 @@
"Connection",
"UnixDomainSocketConnection",
"ClusterConnection",
"BlockingConnectionPool",
"ConnectionPool",
"BlockingClusterConnectionPool",
"ClusterConnectionPool",
"PureToken",
"Sentinel",
"__version__",
]
Loading