Redis python interface that serializes all values using json, pickle, msgpack or a custom serializer.
Project description
Redis python interface that serializes all values using json, pickle, msgpack or a custom serializer.
Getting Started
Installation
pip install serialized-redis-interface
Usage
>>> import serialized_redis
>>> r = serialized_redis.JSONSerializedRedis(host='localhost', port=6379, db=0)
>>> r.set('foo', { 'test': 'dict' })
True
>>> r.get('foo')
{'test': 'dict'}
>>> r = serialized_redis.PickleSerializedRedis(host='localhost', port=6379, db=0)
>>> r.set('foo', { 'test': 'dict' })
True
>>> r.get('foo')
{'test': 'dict'}
>>> r = serialized_redis.MsgpackSerializedRedis(host='localhost', port=6379, db=0)
>>> r.set('foo', { 'test': 'dict' })
True
>>> r.get('foo')
{'test': 'dict'}
serialized-redis extends redis-py and uses the same interface.
Most commands, Piplines and PubSub are supported and take care of serializing and deserializing values.
msgpack must be installed in order to use MsgpackSerializedRedis.
All strings are python str.
Limitations
As values are serialized, Redis operations that manipulate or extract data from values are not supported.
SORT commands may not return correct order depending on the serializer used.
ZSCAN and SSCAN MATCH option will only work for exact match.
STRLENGTH and HSTRLENGTH will return the length of the serialized value.
all lexicographical commands like ZLEXCOUNT, ZREMRANGEBYLEX and ZREVRANGEBYLEX are not supported
INCR is only supported with JSON serializer
fields of Redis hashes are not serialized
Extra Methods
smembers_as_list, sdiff_as_list, sinter_as_list, sunion_as_list can be used when members of the redis set may not be hashable once deserialized.
>>> r = serialized_redis.JSONSerializedRedis() >>> r.sadd('myset', {'dict': 1}) 1 >>> r.smembers('myset') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/michael/workspace/Origin_Nexus/serialized_redis/serialized_redis/__init__.py", line 176, in smembers return set(super().smembers(*args, **kwargs)) TypeError: unhashable type: 'dict' >>> r.smembers_as_list('myset') [{'dict': 1}]
smart_get and smart_set can be used to retrieve and store python structure with their redis counterpart:
python list as redis LIST
python set as redis SET
python dict as redis HASH, fields will not be (de)serialized.
Custom Serializer
You can use your own seriliazing and deserializing functions:
>>> r = serialized_redis.SerializedRedis(serialization_fn=my_serializer, deserialization_fn=my_deserializer)
If your deserializer function expects python 3 strings instead of bytes, you can add decode_responses=True parameter.
Decoding bytes to str when required is the responsability of the deserialization function.
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 serialized-redis-interface-0.3.1.tar.gz
.
File metadata
- Download URL: serialized-redis-interface-0.3.1.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3767257f36981775fb9ff828dfb628b0b55a76a26bed569fd18ede88bc2e1a0c |
|
MD5 | 5633ea954874c0109a837bc7463f9627 |
|
BLAKE2b-256 | 0391e8433f5bda98e3a8c2c6829cb8c1e285d30ab8a1345189c85df600e7f708 |
File details
Details for the file serialized_redis_interface-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: serialized_redis_interface-0.3.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b87a0ebfa4f830091ca2b23805917fe90f412068998d0635c8fca6c0cbf6077b |
|
MD5 | 0f32a5725bd3a377dfd306422c6d208b |
|
BLAKE2b-256 | dddae2eb88e200f855d485c18b108fddeacd7033396617b8bfe4df40a019bcad |