Skip to main content

redis with a simple (dict-like or list-like) interface

Project description

redisdol

redis with a simple (dict-like or list-like) interface

To install: pip install redisdol

Provides a collections.abc.MutableMapping (i.e. dict-like) interface to Redis.

Note that Redis automatically converts everything to bytes when writing, which means that read and write are not inverse of each other in the base RedisPersister. A serialization/deserialization layer can be added to make read and write consistent.

>>> from redisdol import RedisBytesPersister
>>> s = RedisBytesPersister()  # plenty of params possible (all those of redis.Redis), but taking defaults.
>>>
>>> # clear the kehys we'll be using
>>> keys = ['_pyst_test_str', '_pyst_test_int', '_pyst_test_float']
>>> for k in keys:
...     del s[k]
>>>
>>> before_length = len(s)
>>>
>>> s['_pyst_test_str'] = 'hello'
>>> s['_pyst_test_str']  # note you won't be getting a str but bytes
b'hello'
>>>
>>> '_pyst_test_str' in s
>>>
>>> # numbers are converted to strings then bytes
>>> s['_pyst_test_int'] = 42
>>> assert s['_pyst_test_int'] == b'42'
>>> s['_pyst_test_float'] = 3.14
>>> assert s['_pyst_test_float'] == b'3.14'
>>>
>>> assert len(s) == before_length + 3
>>>
>>> '_pyst_test_float' in
>>>
>>> # clean up
>>> for k in keys:
...     del s[k]
>>>

Project details


Download files

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

Source Distribution

redisdol-0.0.3.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

redisdol-0.0.3-py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page