Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

No project description provided

Project description

Redis Shelve

Build status
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for redis-shelve, version 1.0.3
Filename, size File type Python version Upload date Hashes
Filename, size redis_shelve-1.0.3-py3-none-any.whl (5.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size redis-shelve-1.0.3.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page