安装
https://pypi.python.org/pypi/redis/
https://github.com/andymccurdy/redis-py
参照官网,安装命令
sudo pip install redis
或者
sudo easy_install redis
亦或
源码包执行sudo python setup.py install
实例
>>> import redis >>> r = redis.Redis(host="172.16.64.175", port=6379, db=0) >>> r.keys() ['foo', 'news:1000:tags', 'c', 'a', 'mylist', 'mycounter', 'mykey', 'b'] >>> r.set('name', 'yang') True >>> r['sex'] = 'man' >>> r.get('sex') 'man' >>> r.delete('a') 1 >>> r.dbsize() 9L >>> r.save() True >>> r.flushdb() True >>> r.keys() [] >>> r.exists('name') False
时间: 2024-10-13 23:19:36