cement.ext.ext_redis

Cement redis extension module.

class cement.ext.ext_redis.RedisCacheHandler(*args, **kw)[source]

Bases: cement.core.cache.CacheHandler

This class implements the Cache Handler interface. It provides a caching interface using the redis library.

Note This extension has an external dependency on redis. You must include redis in your applications dependencies as Cement explicitly does not include external dependencies for optional extensions.

class Meta[source]

Bases: object

Handler meta-data.

_config(key, default=None)[source]

This is a simple wrapper, and is equivalent to: self.app.config.get('cache.redis', <key>).

Parameters:key (str) – The key to get a config value from the cache.redis config section.
Returns:The value of the given key.
Return type:unknown
_setup(*args, **kw)[source]

Called during application initialization and must setup the handler object making it ready for the framework or the application to make further calls to it.

Parameters:app (instance) – The application object.
delete(key, **kw)[source]

Delete an item from the cache for the given key. Additional keyword arguments are ignored.

Parameters:key (str) – The key to delete from the cache.
get(key, fallback=None, **kw)[source]

Get a value from the cache. Additional keyword arguments are ignored.

Parameters:key (str) – The key of the item in the cache to get.
Keyword Arguments:
 fallback – The value to return if the item is not found in the cache.
Returns:The value of the item in the cache, or the fallback value.
Return type:unknown
purge(**kw)[source]

Purge the entire cache, all keys and values will be lost. Any additional keyword arguments will be passed directly to the redis flush_all() function.

set(key, value, time=None, **kw)[source]

Set a value in the cache for the given key. Additional keyword arguments are ignored.

Parameters:
  • key (str) – The key of the item in the cache to set.
  • value – The value of the item to set.
  • time (int) – The expiration time (in seconds) to keep the item cached. Defaults to expire_time as defined in the applications configuration.