redis-collections is a Python library that provides a high-level interface to Redis, the excellent key-value store.
As of 2024, this project is retired. This repository will remain available as a public archive.
Quickstart
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']
42
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
2
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
1
>>> 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')
200.0
>>> ssc.items()
[('mercury', 100.0), ('venus', 200.0), ('earth', 300.0)]
Documentation
For more information, see redis-collections.readthedocs.io
License: ISC
© 2016-2024 Bo Bayles <bbayles@gmail.com> and contributors © 2013-2016 Honza Javorek <mail@honzajavorek.cz> and contributors
This work is licensed under ISC license.
This library is not affiliated with Redis Labs, Redis, or redis-py. Govern yourself accordingly!
Release files for redis-collections 0.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| redis-collections-0.13.0.tar.gz | 41.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| redis_collections-0.13.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 70.9 kB
Release files / redis-collections-0.13.0.tar.gz
| Download URL | redis-collections-0.13.0.tar.gz |
|---|---|
| Size | 41.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3ac7824e73b2aa47aee9999b73d90ca61d85b59572998b7c6c885da0047c9056
|
|
BLAKE2b-256 checksum How to use checksums |
a02f1dca17c29a7965459ff360a07e86b3aaf78f4b94ae4de746a8727bfb47d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.7
|
Release files / redis_collections-0.13.0-py2.py3-none-any.whl
| Download URL | redis_collections-0.13.0-py2.py3-none-any.whl |
|---|---|
| Size | 29.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a7c41ff0a1135004f3dec98bedabf89592746fe0a2ca4a6ee455fc3cc12f9060
|
|
BLAKE2b-256 checksum How to use checksums |
82d4d1eb9a22fe763d6b04df4002a37643974efb3ceea6326adba4ce45ecfeaf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.7
|