No project description provided
Project description
Redis Shelve
A Python shelve that uses Redis as storage.
Motivation
In some contexts writing state to files can be hard. Redis can be a more suitable storage solution. If you need a shelve but cannot write to file and if you are friends with Redis already, you can use Redis Shelve.
License
Redis Shelve is licensed under LGPLv3. See the LICENSE file for details.
Installation
pip install redis-shelve
Usage
The behaviour of the Redis shelve should be similar to Python shelve. Instead of a filename, you can pass redis-shelve a redis instance. You can think of the configured redis database being similiar to a file in Python shelve.
import redisshelve
from redis import Redis
redis = Redis(db=15)
shelf = redisshelve.RedisShelf(redis=redis)
shelf['test'] = 'Test'
assert 'Test' == shelf['test']
assert 'Test' == shelf.get('test')
You can also use the redisshelve.open
context manager.
with redisshelve.open(redis=redis) as shelf:
shelf['foo'] = 'Bar'
Prefixing keys
By default, the keys you enter in the shelf are used as keys in Redis. If you think this might conflict with existing values, you can prefix your keys.
NB: As a side effect, if you also use writeback, the keys in the shelf's cache are also prefixed.
shelf = redisshelve.RedisShelf(redis=redis, key_prefix='my_prefix')
with redisshelve.open(redis=redis, key_prefix='my_prefix') as shelf:
shelf['foo'] = 'Bar'
More examples.
Please see the tests for more examples.
unprefixed: tests/test_redisshelve_unprefixed.py
prefixed: tests/test_redisshelve_prefixed.py
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-shelve-1.0.3.tar.gz
.
File metadata
- Download URL: redis-shelve-1.0.3.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa9a4b180d8a5e2f65278e29b9801100e30c60ab6c5b59d4afa04df0d9d70874 |
|
MD5 | 95e593053a2aa6d6ef115f5c94bfcc05 |
|
BLAKE2b-256 | a4612587e6f649f08f8749abe0aeb9aea3fa969247f9fb97124a13c00d5281cf |
File details
Details for the file redis_shelve-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: redis_shelve-1.0.3-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fc8924e610c97f9d2508a66b7ae0e17d608246a06094a1a01029574b5689c54 |
|
MD5 | f5a2ebbf3742878d57d4540f4b2d7dcb |
|
BLAKE2b-256 | 5f68495f0efe97037a54109ade4fe84f80cdf8c73a7ad0aee6f12d53bf70983f |