Set of basic Python collections backed by Redis.
Project description
redis-collections is a Python library that provides a high-level interface to Redis, the excellent key-value store.
Quickstart
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']
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
Maintainers
Bo Bayles (@bbayles)
Honza Javorek (@honzajavorek)
License: ISC
© 2016-? 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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file redis-collections-0.9.0.tar.gz
.
File metadata
- Download URL: redis-collections-0.9.0.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10bf290c5dab0aefefa96afa1b4277b23467783af04be3341669797f1b769179 |
|
MD5 | 8eeb231d49e102aa8cdcb887634008e8 |
|
BLAKE2b-256 | 6887d280f69fd076714c5f3d101ef16713a314d32df2c96e37ac6aaca152d3e4 |
File details
Details for the file redis_collections-0.9.0-py2.py3-none-any.whl
.
File metadata
- Download URL: redis_collections-0.9.0-py2.py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64c61eb4f07de5c4038880f354cc8b5406cde59465169625b89679aab457c8db |
|
MD5 | 1b888d529f6b34f744419555c0c0ab7e |
|
BLAKE2b-256 | 1c852f61068008b1f34212a5f2af8467f90cbe2645123079a0b8c6ce601f975b |