Skip to main content

Dictionary with Redis as storage backend

Project description

Redis Dict

Redis Dict

Build Status

Dictionary with Redis as storage backend. Redis is a great database for all kinds of environments; from simple to complex. redis-dict tries to make using Redis as simple as using a dictionary. redis-dict stores data in redis with key values, this is according to Redis best practices. This also allows other non-python programs to access the data stored in redis.

Features

Dictionary

redis-dict can be used in drop in replacement of a normal dictionary as long no referenced datascructed are used. i.e no nested layout e.g values such list, instance and other dictionaries. When used with supported types in can be used a drop in for a normal dictionary.

redis-dict has all the methods and behaviours of a normal dictionary.

Types

Several python types can be saved and retrieved as the same type. As of writing, redis-dict supports the following types.

  • String
  • Integer
  • Float
  • Boolean
  • None

Expire

Redis has the great feature of expiring keys, this feature is supported.

  1. you can set default experition when creating redis-dict instance.
r_dic = RedisDict(namespace='app_name', expire=10)
  1. With context manager you can temporarly set the default expiration time you have set. Defaults to None (do not expire)
seconds = 60
with r_dic.expire_at(seconds):
    r_dic['gone_in_sixty_seconds'] = 'foo'

Batching

Batch your requests by using Pipeline, as easy as using context manager

Example storing the first ten items of fibonacci, with one roundtrip to redis.

def fib(n):
    a, b = 0, 1
    for _ in range(n):
        yield a
        a, b = (a+b), a

with r_dic.pipeline():
    for index, item in enumerate(fib(10)):
        r_dic[str(index)] = item

Namescape

Redis-dict uses namespaces by default. This allows you to have an instance of Redis-dict per project. When looking directly at the data in redis, this gives you the advantage of directly seeing which data belongs to which app. This also has the advantage that it is less likely for apps to collide with keys, which is a difficult problem to debug.

Examples

Here are some more simple examples of Redis-dict. More complex examples of Redis-dict can be found in the tests. All functionality is tested in either assert_test.py (here) or in the unit tests (here).

    >>> from redis_dict import RedisDict
    >>> r_dic = RedisDict(namespace='app_name')
    >>> 'foo' in r_dic
    False
    >>> r_dic['foo'] = 4
    >>> r_dict['foo']
    4
    >>>

Note

This project is used by different companies in production.

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 dict-1.4.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

redis_dict-1.4-py2.py3-none-any.whl (5.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file redis dict-1.4.tar.gz.

File metadata

  • Download URL: redis dict-1.4.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.2

File hashes

Hashes for redis dict-1.4.tar.gz
Algorithm Hash digest
SHA256 ae534bc02e37c66bb809be95db9ccd12c917c9059f2c535e0ffed3c03ecce7da
MD5 e507cdaf1fc6a08300b03793de541263
BLAKE2b-256 16ea2c937a9b92c2039fcdfb5b1be61e38478a4acaccb68d75c9a3e87b1d84a8

See more details on using hashes here.

File details

Details for the file redis_dict-1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: redis_dict-1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.2

File hashes

Hashes for redis_dict-1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 431d4779eb194c50a3d6375257581bc078c4f0b96a5bc99fd8ba275f632e8bb6
MD5 9c5b8992409bdc02147b9b340fd4d274
BLAKE2b-256 697ea6699a04a3ac016d58874a55077cbbc5ff1ede90eeaf8a25d62c5193f954

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