redtrio.midlevel

The Midlevel client is a layer of abstraction above the lowlevel client.

In particular, this means:

  1. Each command has its own function with type hints.

  2. Where possible, arguments supplied to a command will be converted automatically from their type to the bytes that Redis expects to receive.

  3. HELLO 3 is called automatically.

  4. Some return types are changed, where it makes sense. For example, INCRBYFLOAT returns a float instead of the bytes that Redis returns.

Submodules

Package Contents

Classes

MidlevelClient

MidlevelClient is an abstraction on top of the lowlevel client.

class redtrio.midlevel.MidlevelClient(**client_args)

MidlevelClient is an abstraction on top of the lowlevel client.

Parameters

**client_args – any arg accepted by lowlevel.RedisClient.

async call(self, command: str, *args: str)

Send a command to Redis and return the response.

Strings passed to this function will be converted to bytes.

Parameters
  • command (str) – The command to be sent, like “HELLO”.

  • *args (str) – Arguments to be sent with the command.

Returns

The response from Redis.

async hello(self, protocol: int)

Say hello to Redis and let it know what protocol we’re using.

It’s good to be friendly.

Parameters

protocol (int) – The protocol number. Currently 3 is the only option.

Returns

A dict containing the response from Redis.

async hdel(self, key: str, *fields: str)

Implement the HDEL command (https://redis.io/commands/hdel).

async hexists(self, key: str, field: str)

Implement the HEXISTS command (https://redis.io/commands/hexists).

async hget(self, key: str, field: str)

Implement the HGET command (https://redis.io/commands/hget).

async hgetall(self, key: str)

Implement the HGETALL command (https://redis.io/commands/hgetall).

async hincrby(self, key: str, field: str, increment: int)

Implement the HINCRBY command (https://redis.io/commands/hincrby).

async hincrbyfloat(self, key: str, field: str, increment: float)

Implement HINCRBYFLOAT command (https://redis.io/commands/hincrbyfloat).

This command modifies the return response from bytes to float.

Parameters
  • key (str) – the key to increment.

  • field (str) – the field of the key to increment.

  • increment (float) – the amount to increment the field.

Returns

The new value of the field (float).

async hkeys(self, key: str)

Implement the HKEYS command (https://redis.io/commands/hkeys).

async hlen(self, key: str)

Implement the HLEN command (https://redis.io/commands/hlen).

async hmget(self, key: str, *fields: str)

Implement the HMGET command (https://redis.io/commands/hmget).

async hset(self, key: str, *args: str)

Implement the HSET command (https://redis.io/commands/hset).

async hsetnx(self, key: str, field: str, value: str)

Implement the HSETNX command (https://redis.io/commands/hsetnx).

async hstrlen(self, key: str, field: str)

Implement the HSTRLEN command (https://redis.io/commands/hstrlen).

async hvals(self, key: str)

Implement the HVALS command (https://redis.io/commands/hvals).

async sadd(self, key: str, *values: str)

Implement the SADD command (https://redis.io/commands/sadd).

async scard(self, key: str)

Implement the SCARD command (https://redis.io/commands/scard).

async sdiff(self, key: str, *keys: str)

Implement the SDIFF command (https://redis.io/commands/sdiff).

async sdiffstore(self, destination: str, key: str, *keys: str)

Implement the SDIFFSTORE command (https://redis.io/commands/sdiffstore).

async sinter(self, key: str, *keys: str)

Implement the SINTER command (https://redis.io/commands/sinter).

async sinterstore(self, destination: str, key: str, *keys: str)

Implement the SINTERSTORE command (https://redis.io/commands/sinterstore).

async sismember(self, key: str, member: str)

Implement the SISMEMBER command (https://redis.io/commands/sismember).

async smembers(self, key: str)

Implement the SMEMBERS command (https://redis.io/commands/smember).

async smismember(self, key: str, member: str, *members: str)

Implement the SMISMEMBER command (https://redis.io/commands/smismember).

async smove(self, source: str, destination: str, member: str)

Implement the SMOVE command (https://redis.io/commands/smove).

async spop(self, key: str, count: t.Optional[int] = None)

Implement the SPOP command (https://redis.io/commands/spop).

async append(self, key: str, value: str)

Implement the APPEND command (https://redis.io/commands/append).

async bitcount(self, key: str, start: t.Optional[int] = None, end: t.Optional[int] = None)

Implement the BITCOUNT command (https://redis.io/commands/bitcount).

async bitop(self, command: t.Literal[‘AND’, ‘OR’, ‘XOR’, ‘NOT’], destination_key: str, *source_keys: str)

Implement the BITOP command (https://redis.io/commands/bitop).

async bitpos(self, key: str, bit: t.Literal[0, 1], start: t.Optional[int] = None, end: t.Optional[int] = None)

Implement the BITPOS command (https://redis.io/commands/bitpos).

async decr(self, key: str)

Implement the DECR command (https://redis.io/commands/decr).

async decrby(self, key: str, decrement: int)

Implement the DECRBY command (https://redis.io/commands/decrby).

async get(self, key: str)

Implement the GET command (https://redis.io/commands/get).

async getbit(self, key: str, index: int)

Implement the GETBIT command (https://redis.io/commands/getbit).

async getrange(self, key: str, start: int, end: int)

Implement the GETRANGE command (https://redis.io/commands/getrange).

async getset(self, key: str, value: str)

Implement the GETSET command (https://redis.io/commands/getset).

async incr(self, key: str)

Implement the INCR command (https://redis.io/commands/incr).

async incrby(self, key: str, increment: int)

Implement the INCRBY command (https://redis.io/commands/incrby).

async incrbyfloat(self, key: str, increment: float)

Implement the INCRBYFLOAT command (https://redis.io/commands/incrbyfloat).

async mget(self, key: str, *keys: str)

Implement the MGET command (https://redis.io/commands/mget).

async mset(self, key: str, value: str, *more: str)

Implement the MSET command (https://redis.io/commands/mset).

async msetnx(self, key: str, value: str, *more: str)

Implement the MSETNX command (https://redis.io/commands/msetnx).

async set(self, key: str, value: str, *, ex: int = 0, px: int = 0, keepttl: bool = False, nx: bool = False, xx: bool = False)

Implement the SET command (https://redis.io/commands/set).

async setbit(self, key: str, offset: int, value: t.Literal[0, 1])

Implement the SETBIT command (https://redis.io/commands/setbit).

async setrange(self, key: str, offset: int, value: str)

Implement the SETRANGE command (https://redis.io/commands/setrange).

async strlen(self, key: str)

Implement the STRLEN command (https://redis.io/commands/strlen).