py-redis


Namepy-redis JSON
Version 1.1.1 PyPI version JSON
download
home_pagehttps://github.com/pkeilbach/pyredis
SummaryA convenience wrapper for the official Python redis package
upload_time2021-12-13 16:58:50
maintainer
docs_urlNone
authorPascal Keilbach
requires_python>=3.6
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Py-Redis

A convenience wrapper for the [official Python Redis package](https://pypi.org/project/redis/). 
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.

## Object Creation

```python
from pyredis import RedisConnection

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

with RedisConnection(**redis_args) as my_redis:
    my_redis.set('key', 'value')

```

## Redis Get and Set

```python

# 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))

```

## Handle Lists and Dictionaries

```python
from pprint import pprint

# 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)

# 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]))
```

## Fallback

```python
# you can always 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'))
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pkeilbach/pyredis",
    "name": "py-redis",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Pascal Keilbach",
    "author_email": "dev@pk17.org",
    "download_url": "https://files.pythonhosted.org/packages/17/dc/f3972b4358680575e5027d2276c5ffc7b592480e212a9c1a02c06bc16bbc/py-redis-1.1.1.tar.gz",
    "platform": "",
    "description": "# Py-Redis\n\nA convenience wrapper for the [official Python Redis package](https://pypi.org/project/redis/). \nSupports the Python context manager protocol and takes care of (de-)serializing data to JSON, \nas well as helper methods to work on multiple keys.\n\n## Object Creation\n\n```python\nfrom pyredis import RedisConnection\n\n# pass everything you would pass to redis.Redis()\nredis_args = {\n    'host': 'localhost',\n    # 'password': 'my$ecureRed1s',\n    # 'port': 1234,\n}\n\nwith RedisConnection(**redis_args) as my_redis:\n    my_redis.set('key', 'value')\n\n```\n\n## Redis Get and Set\n\n```python\n\n# redis set\nwith RedisConnection(**redis_args) as my_redis:\n    my_redis.set('a_sting', 'my_sting value')\n    my_redis.set('a_list', [1, 4, 3, 2])\n    my_redis.set('a_dict', {'key_1': 'val_1', 'key_2': 'val_2'})\n\n# redis get\nwith RedisConnection(**redis_args) as my_redis:\n    data = my_redis.get('a_dict')\n    # data is already converted to a dict\n    print(type(data))\n\n```\n\n## Handle Lists and Dictionaries\n\n```python\nfrom pprint import pprint\n\n# get multiple keys / data\nwith RedisConnection(**redis_args) as my_redis:\n    # get all keys that start with a_\n    pattern = 'a_'\n    keys = my_redis.get_key_pattern(pattern)\n    print(f\"list of all keys that start with {pattern}: {keys}\")\n    data = my_redis.get_data_for_keys(keys)\n    print(f\"data of all keys that start with {pattern}: {data}\")\n\n    # or retrieve the data as a key: data dictionary for a specific pattern\n    print('data as key: data dictionary for a pattern:')\n    data = my_redis.get_keys('a_')\n    pprint(data)\n\n# set all entries of a dictionary to redis\ndata = {'a': 12, 'b': 'myvalue'}\nwith RedisConnection(**redis_args) as my_redis:\n    # yo can continue working with the keys\n    keys = my_redis.set_dict(data)\n    print(my_redis.get('a'))\n    print(my_redis.get(keys[1]))\n```\n\n## Fallback\n\n```python\n# you can always work directly on the redis.Redis() object, \n# as you would with the official package,\n# by using the RedisConnection.R attribute\nwith RedisConnection(**redis_args) as my_redis:\n    print('access redis client through object...')\n    print(my_redis.R.get('a_dict'))\n```\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A convenience wrapper for the official Python redis package",
    "version": "1.1.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "58bd2c4313dfe3b09e253d64231c3386baca9db6952de7e71996e165428d6e45",
                "md5": "49a6df1ac7b48e46edfd06718c4c194c",
                "sha256": "c6ec84fc8251398236f1c0b98f6ad09dc61667c29664efb7d44e95dc5763782e"
            },
            "downloads": -1,
            "filename": "py_redis-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "49a6df1ac7b48e46edfd06718c4c194c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4407,
            "upload_time": "2021-12-13T16:58:48",
            "upload_time_iso_8601": "2021-12-13T16:58:48.912556Z",
            "url": "https://files.pythonhosted.org/packages/58/bd/2c4313dfe3b09e253d64231c3386baca9db6952de7e71996e165428d6e45/py_redis-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17dcf3972b4358680575e5027d2276c5ffc7b592480e212a9c1a02c06bc16bbc",
                "md5": "5644c31589cf9ed4b46a984d6b402c71",
                "sha256": "f64cfa44dcd69af19348234ba96a2a943e3793248dcbdb267bdefb1751f4002f"
            },
            "downloads": -1,
            "filename": "py-redis-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5644c31589cf9ed4b46a984d6b402c71",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4090,
            "upload_time": "2021-12-13T16:58:50",
            "upload_time_iso_8601": "2021-12-13T16:58:50.738114Z",
            "url": "https://files.pythonhosted.org/packages/17/dc/f3972b4358680575e5027d2276c5ffc7b592480e212a9c1a02c06bc16bbc/py-redis-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-12-13 16:58:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "pkeilbach",
    "github_project": "pyredis",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "py-redis"
}
        
Elapsed time: 0.10580s