Skip to main content

Serialize any python datatypes and does redis actions using redis-py

Project description

Direct-Redis

  • Serialize any python datatypes and executes redis commands using redis-py
  • When loading, it auutomatically converts serialized data into original data types

Getting Started

Install via pypi

pip install direct-redis

Instantiate

from direct_redis import DirectRedis
r = DirectRedis(host='localhost', port=6379)

Supporting Data Types

  • Built-in
    • string
    • number(int, float)
    • dictionary
    • list
    • tuple
    • etc (all other python built-in types)
  • Module Classes
    • pandas
    • numpy

Supporting Redis Commands

  • KEYS
  • TYPE
  • SET
  • GET
  • Hash Functions
    • HSET
    • HMSET
    • HGET
    • HMGET
    • HGETALL
  • Set Functions
    • SADD
    • SMEMBERS
  • List Functions
    • LPUSH
    • RPUSH
    • LRNAGE

Examples

String

  • Originally redis stores string into bytes.
>>> s = "This is a String. \n스트링입니다."
>>> print(s)
This is a String.
스트링입니다.   

>>> r.set('s', s)   

>>> r.get('s')   
'This is a String. \n스트링입니다.'    

>>> type(r.get('s'))
<class 'str'>

Numbers

>>> mapping = {
...     'a': 29,
...     'b': 0.5335113,
...     'c': np.float64(0.243623466363223),
... }   

>>> r.hmset('nums', mapping)   

>>> r.hmget('nums', *mapping.keys())   
[29, 0.5335113, 0.243623466363223]    

>>> list(mapping.values()) == r.hmget('nums', *mapping.keys())
True

Nested Dictionaries and Lists

>>> l = [1,2,3]
>>> d = {'a': 1, 'b': 2, 'c': 3}   

>>> r.hmset('list and dictionary', {'list': l, 'dict': d})   

>>> r.hgetall("list and dictionary")
{'list': [1, 2, 3], 'dict': {'a': 1, 'b': 2, 'c': 3}}

>>> type(r.hgetall("list and dictionary")['list'])
<class 'list'>   

>>> type(r.hgetall("list and dictionary")['dict'])
<class 'dict'>

Pandas DataFrame

>>> df =  pd.DataFrame([[1,2,3,'235', '@$$#@'], 
                       ['a', 'b', 'c', 'd', 'e']])
>>> print(df)
   0  1  2    3      4
0  1  2  3  235  @$$#@
1  a  b  c    d      e   

>>> r.set('df', df)   

>>> r.get('df')
   0  1  2    3      4
0  1  2  3  235  @$$#@
1  a  b  c    d      e   

>>> type(r.get('df'))
<class 'pandas.core.frame.DataFrame'>

Numpy Array

>>> arr = np.random.rand(10).reshape(5, 2)
>>> print(arr)
[[0.25873887 0.00937433]
 [0.0472811  0.94004351]
 [0.92743943 0.93898677]
 [0.87706341 0.85135288]
 [0.06390652 0.86362001]]   

>>> r.set('a', arr)   

>>> r.get('a')   
array([[0.25873887, 0.00937433],
       [0.0472811 , 0.94004351],
       [0.92743943, 0.93898677],
       [0.87706341, 0.85135288],
       [0.06390652, 0.86362001]])   

>>> type(r.get('a'))
<class 'numpy.ndarray'>

Author

direct-redis is developed and maintained by Yonghee Cheon (yonghee.cheon@gmail.com).
It can be found here: https://github.com/yonghee12/direct-redis

Special thanks to:

  • Andy McCurdy, the author of redis-py.

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

direct_redis-0.2.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

direct_redis-0.2.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file direct_redis-0.2.0.tar.gz.

File metadata

  • Download URL: direct_redis-0.2.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.10

File hashes

Hashes for direct_redis-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9077a0c538a874e2b915165f065a79a100c52b58ad55821feeb23bb838768431
MD5 d9d05c7113b837bdcaf27ea936384c6b
BLAKE2b-256 5f5b1c8ba74262e8baf16dd82741cc143f687c213a248321b9b13a3562e4215a

See more details on using hashes here.

File details

Details for the file direct_redis-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: direct_redis-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.10

File hashes

Hashes for direct_redis-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c98740b882433a853b78609e7dfd4b6b54bc9f6581f56c8c6adf7b4512d00f20
MD5 9f563ca7d2f00cc3e177658ad6182d5f
BLAKE2b-256 c6330bc1a0565a3f08082bd825066e8be04f28c7a4292f5d35a0535fd7f64b83

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