In-memory stores¶
The simplest conceivable key-value store is found in
simplekv.memory.DictStore
. It lends itself well for testing or
playing around with simplekv.
-
class
simplekv.memory.
DictStore
(d=None)¶ Store data in a dictionary.
This store uses a dictionary as the backend for storing, its implementation is straightforward. The dictionary containing all data is available as d.
redis-backend¶
The redis-backend requires redis
to be installed and uses a
redis-database as a backend.
Currently, simplekv targets the latest stable redis version, but since it uses very few commands available, it should work on older stables as well. Note that some features are unsupported on older redis-versions (such as sub-second accuracy for TTL values on redis < 2.6) and will cause redis to complain.
-
class
simplekv.memory.redisstore.
RedisStore
(redis)¶ Uses a redis-database as the backend.
Parameters: redis – An instance of redis.StrictRedis
.
memcached-backend¶
The memcached-backend is not fully
KeyValueStore
-compliant, because some operations are not
supported on memcached. An IOError
will be raised if that is
the case.
Due to the nature of memcache, attempting to store objects that are close to 1
megabyte in size or larger will most likely result in an
IOError
, unless you increased memcached‘s limit at compile
time. This store also does not make any guarantees about persistancy, it is as
volatile as memcache itself and best used for caching.
-
class
simplekv.memory.memcachestore.
MemcacheStore
¶ A backend that uses python-memcached or pylibmc to connect to a memcached instance.
Note that
__contains__()
is not supported when using python-memcached, while it usually works with pylibmc.In addition to that, iterating the keys (using
__iter__()
,iter_keys()
) and listing keys throughkeys()
is not supported at all [1].-
__init__
(mc)¶ Parameters: mc – A Client
instance of python-memcached or pylibmc.
-
[1] | The memcached protocol does not support listing/iterating over keys. |