Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

About

Simple redis-py wrapper library

Resources

License

Packages

No packages published

Languages

You can’t perform that action at this time.