Skip to main content

An async redis client library with a minimal api

Project description

reddish - an redis client for sockets and trio with minimal api

Features

  • both sync and async API
  • sync api using the standard library socket module (TPC, TPC+TLS, Unix domain sockets)
  • async/await using trio's stream primitives (TCP, TCP+TLS, Unix domain sockets)
  • minimal api so you don't have to relearn how to write redis commands
  • supports all redis commands including modules except SUBSCRIBE, PSUBSCRIBE and MONITOR [^footnote]
  • parses responses back into python types if you like (powered by pydantic)
  • works with every redis version and supports both RESP2and RESP3 protocols

[^footnote]: Commands like SUBSCRIBE or MONITOR take over the redis connection for listeting to new events barring regular commands from being issued over the connection.

Installation

pip install reddish  # install just with support for socket
pip install reddish[trio]  # install with support for trio

Minimal Example - sync version

import socket
from reddish.socket import Redis, Command

redis = Redis(socket.create_connection(('localhost', 6379)))

assert b'PONG' == redis.execute(Command('PING'))

Minimal Example - async version

import trio
from reddish.trio import Redis, Command

redis = Redis(await trio.open_tcp_stream('localhost', 6379))

assert b'PONG' == await redis.execute(Command('PING'))

Usage

Command with a fixed number of arguments

# simple command without any arguments
Command('PING')

# commands with positional arguments
Command('ECHO {}', 'hello world')

# commands with keyword arguments
Command('SET {key} {value}', key='foo', value=42)

Command with response parsing

# return response unchanged from redis
assert b'42' == await redis.execute(Command('ECHO {}', 42))

# parse response as type
assert 42 == await redis.execute(Command('ECHO {}', 42).into(int))

# use any type that works with pydantic
from pydantic import Json
import json

data = json.dumps({'alice': 30, 'bob': 42})
response == await redis.execute(Command('ECHO {}', data).into(Json))
assert response == json.loads(data)

Command with variadic arguments

from reddish.trio import Args

# inlining arguments
Command('DEL {keys}', keys=Args(['foo', 'bar']))  # DEL foo bar

# inlining pairwise arguments 
data = {'name': 'bob', 'age': 42}
Command('XADD foo * {fields}', fields=Args.from_dict(data))  # XADD foo * name bob age 42

Pipelining commands

foo, bar = await redis.execute_many(Command('GET', 'foo'), Command('GET', 'bar'))

Transactions

from reddish.trio import MultiExec

tx = MultiExec(
    Command('ECHO {}', 'foo'),
    Command('ECHO {}', 'bar')
)

foo, bar = await redis.execute(tx)

# pipelining together with transactions
[foo, bar], baz = await redis.execute_many(tx, Command('ECHO {}', 'baz'))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reddish-0.4.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

reddish-0.4.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file reddish-0.4.0.tar.gz.

File metadata

  • Download URL: reddish-0.4.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.9.9 Linux/5.11.0-1021-azure

File hashes

Hashes for reddish-0.4.0.tar.gz
Algorithm Hash digest
SHA256 9ad199cd869e97cc6d0440dab56d1b7f1f4c012de0b884aea6845e05259d9a81
MD5 9209be76d7c2c2c4ae9536ab39f1e8a4
BLAKE2b-256 8f7f1c9e895c5d3feb265c2f7ecec9c6dfeb91f30e7edb4c3ba1b384c34ecef8

See more details on using hashes here.

File details

Details for the file reddish-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: reddish-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.9.9 Linux/5.11.0-1021-azure

File hashes

Hashes for reddish-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3926ecb78d63fbdb5b1d58704f59d5fb4a30bf03ea64e71ffc3764c5ead87cfa
MD5 4d14a874964bcbc01efd7c853d9d04a1
BLAKE2b-256 08f9e93b64f98127a9f8a941711bde3999b2305b0ab4e6e363e123830f7a0dac

See more details on using hashes here.

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