Skip to main content

Redis client with msgpack serialization

Project description

redis-msgpack

A Python Redis client that uses MessagePack serialization for efficient data storage and retrieval.

PyPI version Python versions License

Features

  • Drop-in replacement for the standard Redis-py client
  • Automatic MessagePack serialization and deserialization
  • Significantly reduced memory usage and network transfer
  • Full support for all Redis data types and commands
  • Django cache backend integration
  • Type hints for better IDE support

Installation

pip install redis-msgpack

With Django integration:

pip install redis-msgpack[django]

Basic Usage

from redis_msgpack import RedisMsgpackClient

# Connect to Redis
client = RedisMsgpackClient(host='localhost', port=6379, db=0)

# Store Python objects directly - they will be serialized with msgpack
client.set('user:profile', {
    'username': 'johndoe',
    'email': 'john@example.com',
    'preferences': ['dark_mode', 'notifications_on'],
    'login_count': 42,
    'last_login': 1647853426.78
})

# Retrieve and automatically deserialize
user_profile = client.get('user:profile')
print(user_profile['username'])  # 'johndoe'

Django Integration

Add to your Django settings:

CACHES = {
    "default": {
        "BACKEND": "redis_msgpack.django_integration.RedisMsgpackCache",
        "LOCATION": "redis://127.0.0.1:6379/1",
        "OPTIONS": {
            "CLIENT_CLASS": "redis_msgpack.client.RedisMsgpackClient",
            "SERIALIZER_CLASS": "redis_msgpack.utils.MsgpackSerializer",
        }
    }
}

Then use Django's cache as usual:

from django.core.cache import cache

# Store complex data
cache.set('key', {'complex': 'data', 'numbers': [1, 2, 3]})

# Retrieve data
data = cache.get('key')

Advanced Usage

Pipeline Support

with client.pipeline() as pipe:
    pipe.set('key1', 'value1')
    pipe.set('key2', [1, 2, 3, 4])
    pipe.hset('hash1', mapping={'field1': 'value1', 'field2': 'value2'})
    result = pipe.execute()

PubSub Support

pubsub = client.pubsub()
pubsub.subscribe('channel1')

# Process messages
for message in pubsub.listen():
    if message['type'] == 'message':
        print(f"Received: {message['data']}")

Custom Serialization Options

from redis_msgpack import RedisMsgpackClient
from redis_msgpack.utils import MsgpackSerializer

# Configure custom serialization options
serializer = MsgpackSerializer(use_bin_type=True, use_single_float=False)
client = RedisMsgpackClient(host='localhost', port=6379, serializer=serializer)

Performance Comparison

When compared to standard JSON serialization, redis-msgpack typically provides:

  • 20-30% smaller serialized data size
  • 10-20% faster serialization/deserialization
  • Full support for binary data without additional encoding

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

redis_msgpack-0.1.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redis_msgpack-0.1.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file redis_msgpack-0.1.1.tar.gz.

File metadata

  • Download URL: redis_msgpack-0.1.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for redis_msgpack-0.1.1.tar.gz
Algorithm Hash digest
SHA256 52bb5c4a38324ee043b0f0184c16297c27e4801758875629ff968f1488ca997c
MD5 660f3905e8d4912f3d20830c528df626
BLAKE2b-256 fe60eccfeb650a1cb9d27f76fae57d45e8c53874163b39b638e5ed618fede436

See more details on using hashes here.

File details

Details for the file redis_msgpack-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: redis_msgpack-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for redis_msgpack-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ea32266b15d8e8b575ac917866b7384680fb14365a0b70d0102198685796e8c0
MD5 9aa6ff6496dc1cd1f6e35cc63e9fbfeb
BLAKE2b-256 050f488a51fcf2ebf963236e0495e289ddbcbad96022b42939692ec03e473d07

See more details on using hashes here.

Supported by

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