Simple redis-py wrapper library
Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
gxredis Support python3 Dec 30, 2016
test Support python3 Dec 30, 2016
.gitignore Initial commit Dec 21, 2016
LICENSE Initial commit Dec 21, 2016
MANIFEST.in Update setup.py and README Dec 30, 2016
README.rst Add install instruction Dec 30, 2016
setup.py Update version to 0.2.1 Dec 30, 2016
tox.ini Support python3 Dec 30, 2016

README.rst

gxredis

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