Set of basic Python collections backed by Redis
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
docs Clarify pickle protocol support Nov 25, 2016
tests Placate pycodestyle 2.0.0 Nov 25, 2016
.coveragerc Add .coveragerc Aug 2, 2016
.gitignore Documentation. Jan 9, 2013
.travis.yml Test against Python 3.6 Dec 24, 2016
LICENSE I like to call myself Honza instead of Jan, also e-mail update Jul 27, 2016 Final packaging cleanup. Jan 18, 2013
README.rst Add SyncableDeque to README Oct 1, 2016
requirements.txt Add six to requirements.txt Jul 30, 2016
setup.cfg Placate pycodestyle 2.0.0 Nov 25, 2016 Make keywords a list Oct 8, 2016


Redis Collections

redis-collections is a Python library that provides a high-level interface to Redis, the excellent key-value store.


Install the library with pip install redis-collections. Import the collections from the top-level redis_collections package.

Standard collections

The standard collections (e.g. Dict, List, Set) behave like their Python counterparts:

>>> from redis_collections import Dict, List, Set

>>> D = Dict()
>>> D['answer'] = 42
>>> D['answer']
Collection Redis type Description
Dict Hash Emulates Python's dict
List List Emulates Python's list
Set Set Emulates Python's set
Counter Hash Emulates Python's collections.Counter
DefaultDict Hash Emulates Python's collections.defaultdict
Deque List Emulates Python's collections.deque

Syncable collections

The syncable collections in this package provide types whose contents are kept in memory. When their sync method is called those contents are written to Redis:

>>> from redis_collections import SyncableDict

>>> with SyncableDict() as D:
...     D['a'] = 1  # No write to Redis
...     D['a'] += 1  # No read from or write to Redis
>>> D['a']  # D.sync() is called at the end of the with block
Collection Python type Description
SyncableDict dict Syncs to a Redis Hash
SyncableList list Syncs to a Redis List
SyncableSet set Syncs to a Redis Set
SyncableCounter collections.Counter Syncs to a Redis Hash
SyncableDeque collections.deque Syncs to a Redis List
SyncableDefaultDict collections.defaultdict Syncs to a Redis Hash

Other collections

The LRUDict collection stores recently used items in in memory. It pushes older items to Redis:

>>> from redis_collections import LRUDict

>>> D = LRUDict(maxsize=2)
>>> D['a'] = 1
>>> D['b'] = 2
>>> D['c'] = 2  # 'a' is pushed to Redis and 'c' is stored locally
>>> D['a']  # 'b' is pushed to Redis and 'a' is retrieved for local storage
>>> D.sync()  # All items are copied to Redis

The SortedSetCounter provides access to the Redis Sorted Set type:

>>> from redis_collections import SortedSetCounter

>>> ssc = SortedSetCounter([('earth', 300), ('mercury', 100)])
>>> ssc.set_score('venus', 200)
>>> ssc.get_score('venus')
>>> ssc.items()
[('mercury', 100.0), ('venus', 200.0), ('earth', 300.0)]


For more information, see


License: ISC

© 2013-? Honza Javorek <mail@honzajavorek>

This work is licensed under ISC license.