Skip to main content

Simple redis-py wrapper library

Project description

Simple redis-py wrapper library

Installation

To install gxredis, simply:

$ sudo pip install gxredis

Usage

>>> import redis
>>> from gxredis import *

>>> class ItemDao(RedisDao):
>>>        item = RedisString("device:{device_id}:item:{item_id}")
>>>        item_list = RedisList("device:{device_id}:list")
>>>        item_set = RedisSet("device:{device_id}:set")
>>>        item_hash = RedisHash("device:{device_id}:hash")
>>>        item_zset = RedisSortedSet("device:{device_id}:zset")

>>> client = redis.StrictRedis("localhost", 6379, 15)
>>> dao = ItemDao(client, key_params={"device_id": "GX123"})

>>> dao.item
RedisString(key="device:{device_id}:item:{item_id}", key_params={'device_id': 'GX123'})

>>> dao.item_list
RedisList(key="device:{device_id}:list", key_params={'device_id': 'GX123'})

>>> dao.item(item_id=1).set("item01")
True

>>> dao.item(item_id=1).get()
'item01'

>>> pipe = dao.pipeline()
>>> accr1 = pipe.item(item_id=1)     # accessor for item01
>>> accr2 = pipe.item(item_id=2)     # accessor for item02
>>> accr1.set("item01")
>>> accr2.set("item02")
>>> pipe.item_list.rpush(accr1.key)
>>> pipe.item_list.rpush(accr2.key)
>>> pipe.execute()

>>> dao.item_list.lrange(0, 100)
['device:GX123:item:1', 'device:GX123:item:2']

LICENSE

  • MIT

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

gxredis-0.3.1.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

gxredis-0.3.1-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

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