Skip to main content
https://travis-ci.org/vladimirshkoda/redis-bindings.svg?branch=master https://img.shields.io/badge/style-wemake-000000.svg

Redis bindings is an attempt to bring Redis types into Python as native ones. It is based on redis-py and has the following types implemented so far:

Moreover, it provides some Redis descriptor interfaces:

  • IRedisField

  • IRedisListField

It is exactly interfaces, because it requires user to override get_key_name method to define key name for Redis. Here is an example of how it can be implemented (can be found in example.py).

from redis import Redis
from redistypes.descriptors import IRedisField, IRedisListField


r_connection = Redis()


class RedisField(IRedisField):
    def __init__(self, pickling=True):
        super(RedisField, self).__init__(
            redis_connection=r_connection,
            pickling=pickling
        )

    def get_key_name(self, instance):
        return ':'.join([
            instance.__class__.__name__, str(instance.pk), self.name
        ])


class RedisListField(IRedisListField, RedisField):
    pass


class Student:
    name = RedisField()
    subjects = RedisListField()

    def __init__(self, pk):
        self.pk = pk

The Student class defined above can do the following things:

>>> from example import Student
>>> s = Student(pk=1)
>>> s.name = 'John Galt'
>>> s.subjects = ['math', 'physics']
>>> s.name
John Galt
>>> s.subjects
RedisList: ['math', 'physics']
>>> s.subjects.append('p.e.')
>>> s.subjects
RedisList: ['math', 'physics', 'p.e.']
>>> # Values stored inside the Redis types are immutable!
>>> s.subjects.append({'name': 'art', 'avg_score': 4.5})
>>> s.subjects[3]
{'avg_score': 4.5, 'name': 'art'}
>>> s.subjects[3]['avg_score'] = 3
>>> s.subjects[3]
{'avg_score': 4.5, 'name': 'art'}

Warning!

All values stored inside the Redis types are immutable! As the example above shows, an attempt to change the value stored in the dictionary inside the RedisList leads to nothing.

Roadmap

  • Querying over the pipe

  • RedisDict

Release files for redistypes 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redistypes 0.2.0
File Size Uploaded
redistypes-0.2.0.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for redistypes 0.2.0
File Interpreter ABI Platform
redistypes-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / redistypes-0.2.0.tar.gz

Download URL redistypes-0.2.0.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2c87966b5c0b27ffbc75e0d3acf97ee949929643ffae06d54d2fe69b4e18ea0d
BLAKE2b-256 checksum
How to use checksums
e532e2137ab35ffea24fb74fc90b0b9d1d6b4d95e092c6ce1d0983057856971f
Upload date
Uploaded using Trusted Publishing?
What is 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.6

Release files / redistypes-0.2.0-py3-none-any.whl

Download URL redistypes-0.2.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38ecc3796e12192c31b2fa7d4ebe3f66788412306137b03bd0beaed107f8d2a3
BLAKE2b-256 checksum
How to use checksums
556388531c600bcc875400758983bf30bf1e77c96ddf6fc895abf82b3dc8ebbb
Upload date
Uploaded using Trusted Publishing?
What is 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.6

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page