Skip to main content

A convenience wrapper for the official Python redis package

Project description

Py-Redis

A convenience wrapper for the official Python Redis package. Supports the Python context manager protocol and takes care of (de-)serializing data to JSON as well as helper methods to work on multiple keys.

from pyredis import RedisConnection
from pprint import pprint

redis_args = {
    # pass everything you would pass to redis.Redis()
    'host': 'localhost',
    # 'password': 'my$ecureRed1s',
    # 'port': 1234,
}

# redis set
with RedisConnection(**redis_args) as my_redis:
    my_redis.set('a_sting', 'my_sting value')
    my_redis.set('a_list', [1, 4, 3, 2])
    my_redis.set('a_dict', {'key_1': 'val_1', 'key_2': 'val_2'})

# redis get
with RedisConnection(**redis_args) as my_redis:
    data = my_redis.get('a_dict')
    # data is already converted to a dict
    print(type(data))

# get multiple keys / data
with RedisConnection(**redis_args) as my_redis:
    # get all keys that start with a_
    pattern = 'a_'
    keys = my_redis.get_key_pattern(pattern)
    print(f"list of all keys that start with {pattern}: {keys}")
    data = my_redis.get_data_for_keys(keys)
    print(f"data of all keys that start with {pattern}: {data}")

    # or retrieve the data as a key: data dictionary for a specific pattern
    print('data as key: data dictionary for a pattern:')
    data = my_redis.get_keys('a_')
    pprint(data)

# or work directly on the redis.Redis() object as you would with the official package
# by using the RedisConnection.R attribute
with RedisConnection(**redis_args) as my_redis:
    print('access redis client through object...')
    print(my_redis.R.get('a_dict'))

# set all entries of a dictionary to redis
data = {'a': 12, 'b': 'myvalue'}
with RedisConnection(**redis_args) as my_redis:
    # yo can continue working with the keys
    keys = my_redis.set_dict(data)
    print(my_redis.get('a'))
    print(my_redis.get(keys[1]))

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

py-redis-1.0.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

py_redis-1.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file py-redis-1.0.2.tar.gz.

File metadata

  • Download URL: py-redis-1.0.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.2

File hashes

Hashes for py-redis-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6ab1afbede3a79e34edc9d3b98cf1f1e45aac7270d9b6c17a6b9e439e6bdf67c
MD5 0e903e09d944a341a235d7a5543159ce
BLAKE2b-256 8552e801c500253f04b86ee46cfc4afc018bc297083ed431bb5e18309b3521dd

See more details on using hashes here.

File details

Details for the file py_redis-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: py_redis-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.2

File hashes

Hashes for py_redis-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1618593e8e80d979f1fa25c86ccf90eb5a922d37f97fa77ec1fbc3abad12d9f9
MD5 020dcf8bffc19751cd3afcc997200bc5
BLAKE2b-256 c4197b789ca9466c4d62e606d407c59622073c0527b704b28969ffc68a67a063

See more details on using hashes here.

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