on Fedora:
安装:
#yum install redis python-redis
#service redis start
检查服务是否工作:
$ redis-cli ping
PONG
简单使用:
In [1]: import redis
In [2]: r = redis.Redis('127.0.0.1')
In [3]: r.set("name", "yourname")
Out[3]: True
In [4]: r.get("name")
Out[4]: 'yourname'
In [5]: r.set("number", 3)
Out[5]: True
In [6]: r.incr("number", 5)
Out[6]: 8
In [7]: r.decr("number", 2)
Out[7]: 6
In [8]: r.incr("number", -1)
Out[8]: 5
In [9]: r.rpush("list", "abc")
Out[9]: 1L
In [11]: r.rpush("list", "def")
Out[11]: 2L
In [12]: r.rpush("list", "ghi")
Out[12]: 3L
In [14]: r.lrange("list", 0, 0)
Out[14]: ['abc']
In [15]: r.lrange("list", 0, -1)
Out[15]: ['abc', 'def', 'ghi']
In [16]: r.lrange("list", 0, -2)
Out[16]: ['abc', 'def']
In [17]: r.lrange("list", 0, 2)
Out[17]: ['abc', 'def', 'ghi']
In [18]: r.lpush("list", '123')
Out[18]: 4L
In [19]: r.lrange("list", 0, 3)
Out[19]: ['123', 'abc', 'def', 'ghi']
In [20]: r.llen("list")
Out[20]: 4
In [21]: r.rename("list", 'w')
Out[21]: True
In [24]: r.lrange('w', 0, -1)
Out[24]: ['123', 'abc', 'def', 'ghi']
In [28]: r.save()
Out[28]: True
In [29]: r.flushall()
Out[29]: True
In [30]: r.keys()
Out[30]: []
阅读(6343) | 评论(0) | 转发(0) |