objects

class async_redis_objects.objects.Set(key, client, encoder, decoder)

Interface to a redis set.

Can be constructed directly, or from an ObjectClient factory.

Parameters
  • key (str) – key in the redis server that is empty, or pointing to an existing set

  • client (Redis) –

async add(*values)

Add one or more values to the set.

Parameters

values – All arguments are treated as items to add.

Return type

int

Returns

Number of items added to the set

async has(value)

Test if a value is in the set already

Parameters

value – Possible value within the set.

Returns

boolean, true if value is in set.

async all()

Load the entire set.

Return type

Set[Any]

async size()

Get the number of items in the set.

Return type

int

async remove(value)

Remove value from the set

Parameters

value – Possible value in the set.

Return type

bool

Returns

True if the field was removed.

async clear()

Clear all values in the set.

Removes the top level key from the redis database.

class async_redis_objects.objects.Hash(key, client, encoder, decoder)

Interface to a redis hash.

Can be constructed directly, or from an ObjectClient factory.

Parameters
  • key (str) – key in the redis server that is empty, or pointing to an existing hash

  • client (Redis) –

async set(key, value)

Set the value of a field in the hash.

Parameters
  • key (str) – Key within the hash table.

  • value – Unserialized value to write to the hash table.

Return type

bool

Returns

True if the key is new.

async add(key, value)

Add a field to the hash table.

If a field with that key already exists, this operation does nothing.

Parameters
  • key (str) – Key within the hash table.

  • value – Unserialized value to write to the hash table.

Return type

bool

Returns

True if the value has been inserted.

async get(key)

Read a field from the hash.

Parameters

key (str) – Possible key within the hash table.

Returns

Value if found, None otherwise.

async mget(keys)

Read a set of fields from the hash.

Parameters

keys (Iterable[str]) – Sequence of potential keys to load from the hash.

Return type

Dict[str, Any]

async all()

Load the entire hash as a dict.

Return type

Dict[str, Any]

async keys()

Read all the keys in the hash.

Return type

Set[str]

async size()

Get the number of items in the hash table.

Return type

int

async delete(key)

Remove a field from the hash.

Parameters

key – Possible key within the hash table.

Return type

bool

Returns

True if the field was removed.

async clear()

Clear all values in the hash.

Removes the top level key from the redis database.

class async_redis_objects.objects.Queue(key, client, encoder, decoder)

A queue interface to a redis list.

Can be constructed directly, or from an ObjectClient factory.

async push(data)

Push an item to the queue.

Parameters

data – Item to push into queue.

async pop(timeout=1)

Pop an item from the front of the queue.

Parameters

timeout (int) – Maximum time to wait for an item to become available in seconds.

Return type

Any

async pop_ready()

Pop an item from the front of the queue if it is immediately available.

Return type

Any

async clear()

Drop all items from the queue.

async length()

Number of items in the queue.

class async_redis_objects.objects.PriorityQueue(key, client, encoder, decoder)

A priority queue interface to a redis sorted set.

Can be constructed directly, or from an ObjectClient factory.

async push(data, priority=0)

Push an item to the queue.

If data is already in the queue, reset its priority.

Parameters
  • data – Item to push into queue.

  • priority – Sorting priority within the queue.

async pop(timeout=1)

Pop the highest priority item from the queue.

Parameters

timeout (int) – Maximum time to wait in seconds for an item to become available.

Return type

Any

async pop_ready()

Pop the highest priority item from the queue if one is available immediately.

Return type

Any

async clear()

Drop all items from the queue.

async score(item)

Get the current priority of item.

async rank(item)

Get the distance of item from the front of the queue.

async length()

Number of items in the queue.

class async_redis_objects.objects.LockContext(name, client, max_duration, timeout)
class async_redis_objects.objects.Publisher(default_channel, client, encoder)
async send(message=None, json=None, channel=None)
async listeners()

Number of subscribers listening on the default channel of this publisher.

Note: A significant caveat of this from redis is this is only those subscribed to the

channel directly. An unknown number of additional listeners on patterns that include this channel may also exist.

Return type

int

class async_redis_objects.objects.ObjectClient(redis_client, encoder=None, decoder=None)

A client object to represent a redis server.

Can be used as a factory to access data structures in the server as python objects.

queue(name, encoder=None, decoder=None)

Load a list to be used as a queue.

Return type

Queue

priority_queue(name, encoder=None, decoder=None)

Load a stateful-set to be used as a priority queue.

Return type

PriorityQueue

hash(name, encoder=None, decoder=None)

Load a hashtable.

Return type

Hash

set(name, encoder=None, decoder=None)

Load a set.

Return type

Set

lock(name, max_duration=60, timeout=None)

A redis resident lock to create mutex blocks across devices.

Parameters
  • name (str) – A unique identifier for the lock

  • max_duration (int) – Max time to hold the lock in seconds

  • timeout (Optional[int]) – Max time to wait to acquire the mutex

Returns

publisher(channel, encoder=None)

Generate a publisher for redis’ PUBSUB system.

Parameters
  • channel – Channel this publisher writes to by default.

  • encoder – Method to transform messages into strings to broadcast

Return type

Publisher