ring.func.asyncio — collection of asyncio factory functions.

This module includes building blocks and storage implementations of Ring factories for asyncio.

ring.func.asyncio.aiomcache(client, key_prefix=None, expire=0, coder=None, user_interface=(<class 'ring.func.asyncio.CacheUserInterface'>, <class 'ring.func.asyncio.BulkInterfaceMixin'>), storage_class=<class 'ring.func.asyncio.AiomcacheStorage'>, key_encoding='utf-8', **kwargs)

Memcached interface for asyncio.

Expected client package is aiomcache.

aiomcache expect Memcached client or dev package is installed on your machine. If you are new to Memcached, check how to install it and the python package on your platform.

Parameters:
  • client (aiomcache.Client) –

    aiomcache client object. See aiomcache.Client().

    >>> client = aiomcache.Client('127.0.0.1', 11211)
    
  • key_refactor (object) – The default key refactor may hash the cache key when it doesn’t meet Memcached key restriction.
See:

ring.func.asyncio.CacheUserInterface() for single access sub-functions.

See:

ring.func.asyncio.BulkInterfaceMixin() for bulk access sub-functions.

See:

ring.func.sync.memcache() for non-asyncio version.

ring.func.asyncio.aioredis(redis, key_prefix=None, expire=None, coder=None, user_interface=(<class 'ring.func.asyncio.CacheUserInterface'>, <class 'ring.func.asyncio.BulkInterfaceMixin'>), storage_class=<class 'ring.func.asyncio.Aioredis2Storage'>, **kwargs)

Redis interface for asyncio.

Expected client package is aioredis.

aioredis expect Redis client or dev package is installed on your machine. If you are new to Memcached, check how to install it and the python package on your platform.

Note that aioredis>=2.0.0 only supported.

Parameters:client (Union[aioredis.Redis,Callable[..aioredis.Redis]]) –

aioredis interface object. See aioredis.create_redis() or aioredis.create_redis_pool(). For convenience, a coroutine returning one of these objects also is proper. It means next 2 examples working almost same:

>>> redis = await aioredis.create_redis(('127.0.0.1', 6379))
>>> @ring.aioredis(redis)
>>> async def by_object(...):
>>>     ...
>>> redis_coroutine = aioredis.create_redis(('127.0.0.1', 6379))
>>> @ring.aioredis(redis_coroutine)
>>> async def by_coroutine(...):
>>>     ...

Though they have slightly different behavior for .storage.backend:

>>> assert by_object.storage.backend is by_object
>>> assert by_coroutine.storage.backend is not redis_coroutine
>>> assert isinstance(
...     await by_coroutine.storage.backend, aioredis.Redis)
See:ring.func.asyncio.CacheUserInterface() for single access sub-functions.
See:ring.func.asyncio.BulkInterfaceMixin() for bulk access sub-functions.
See:ring.redis() for non-asyncio version.
ring.func.asyncio.dict(obj, key_prefix=None, expire=None, coder=None, user_interface=<class 'ring.func.asyncio.CacheUserInterface'>, storage_class=None, **kwargs)

dict interface for asyncio.

See:ring.func.sync.dict() for common description.
ring.func.asyncio.create_asyncio_factory_proxy(factory_table, *, support_asyncio)
ring.func.asyncio.convert_storage(storage_class)
ring.func.asyncio.create_factory_from(sync_factory, _storage_class)

Create asyncio compatible factory from synchronous storage.

class ring.func.asyncio.CacheUserInterface(ring)

General cache user interface provider for asyncio.

See:ring.func.base.BaseUserInterface for class and methods details.
class ring.func.asyncio.BulkInterfaceMixin

Bulk access interface mixin.

Any corresponding storage class must be a subclass of ring.func.asyncio.BulkStorageMixin.

delete_many(wire, pargs)

Delete the storage values of the corresponding keys.

See:The class documentation for the parameter details.
Return type:None
execute_many(wire, pargs)

Execute and return the results of the original function.

See:The class documentation for the parameter details.
Returns:A sequence of the results of the original function.
Return type:Sequence of the return type of the original function
get_many(wire, pargs)

Try to get and returns the storage values.

See:The class documentation for the parameter details.
Returns:A sequence of the storage values or miss_value for the corresponding keys. When a key exists in the storage, the matching value is selected; Otherwise the miss_value of Ring object is.
get_or_update_many(wire, pargs)

Try to get and returns the storage values.

Note:The semantics of this function may vary by the implementation.
See:The class documentation for the parameter details.
Returns:A sequence of the storage values or the executed result of the original function for the corresponding keys. When a key exists in the storage, the matching value is selected; Otherwise, the result of the original function is.
has_many(wire, pargs)

Return whether the storage has values of the corresponding keys.

See:The class documentation for the parameter details.
Return type:Sequence[bool]
set_many(wire, pargs)

Set the storage values of the corresponding keys as the given values.

See:The class documentation for common parameter details.
Parameters:value_list (Iterable[Any]) – A list of the values to save in the storage.
Return type:None
touch_many(wire, pargs)

Touch the storage values of the corresponding keys.

See:The class documentation for the parameter details.
Return type:None
update_many(wire, pargs)

Execute the original function and set the result as the value.

See:The class documentation for the parameter details.
Returns:A sequence of the results of the original function.
Return type:Sequence of the return type of the original function
class ring.func.asyncio.BulkStorageMixin
delete_many(keys)

Delete values for the given keys.

get_many(keys, miss_value)

Get and return values for the given key.

has_many(keys)

Check and return existences for the given keys.

set_many(keys, values, expire=Ellipsis)

Set values for the given keys.

touch_many(keys, expire=Ellipsis)

Touch values for the given keys.

class ring.func.asyncio.AiomcacheStorage(ring, backend)

Storage implementation for aiomcache.Client.

delete_many_values(keys)
delete_value(key)

Delete value for the given key.

get_many_values(keys)
get_value(key)

Get and return value for the given key.

set_many_values(keys, values, expire)
set_value(key, value, expire)

Set value for the given key, value and expire.

touch_value(key, expire)

Touch value for the given key. (optional)