python-redis
来源:互联网 发布:淘宝买洗衣机可靠吗 编辑:程序博客网 时间:2024/05/01 23:18
python-redis
首先确保redis已经正常启动。
安装
可以去pypi上找到redis的Python模块:
http://pypi.python.org/pypi?%3Aaction=search&term=redis&submit=search
然后按照提示down下来redis-py-2.2.1.tar.gz
非常标准的解压: #tar xvzf redis-py-2.2.1.tar.gz
进入解压目录,进行Python模块的标准安装:
python setup.py install
运行
打开Python解释器:
>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0) #如果设置了密码,就加上password=密码
>>> r.set('foo', 'bar') #或者写成 r['foo'] = 'bar'
True
>>> r.get('foo')
'bar'
>>> r.delete('foo')
True
>>> r.dbsize() #库里有多少key,多少条数据
0
>>> r['test']='OK!'
>>> r.save() #强行把数据库保存到硬盘。保存时阻塞
True
--------------------------------
>>> r.flushdb() #删除当前数据库的所有数据
True
>>> a = r.get('chang')
>>> a # 因为是Noen对象,什么也不显示!
>>> dir(a)
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
>>> r.exists('chang') #看是否存在这个键值
False
>>> r.keys() # 列出所有键值。(这时候已经存了4个了)
['aaa', 'test', 'bbb', 'key1']
附注A:
来看一下redis.Redis的 init() 函数定义:
__init__(self, host='localhost', port=6379, db=0, password=None, socket_timeout=None, connection_pool=None, charset='utf-
8', errors='strict', decode_responses=False, unix_socket_path=None)
最新的redis 2.6.0加入了连接池,具体用法可以看作者博客。
附注B:
其他命令API,请参照redis-Python作者的博客,写的挺清楚了:
https://github.com/andymccurdy/redis-py
- python redis
- python-redis
- python-redis
- Python-Redis
- python-redis
- python redis
- python redis
- python redis
- [Python]python连接redis
- Redis in Python-----redis module
- redis -- python操作连接redis
- Redis in Python:Redis数据类型
- Python操作redis
- redis python接口问题
- python redis用法
- python的redis用法
- Python Redis 数据复制
- python简单操作redis
- 提防toString递归问题
- FMS安装调试心得
- cocos2d-html5 简易选项卡组件 源码 与实现方法
- python操作redis简单例子
- STL 总结
- python-redis
- bzoj2658: [Zjoi2012]小蓝的好友(mrx)
- NSMUtableDictonary常用用法
- python的redis用法
- 【js设计模式笔记---单体模式】
- Java的访问级别:public(公共),protected(保护),private(私有)
- python&php数据抓取、爬虫分析与中介,有网址案例
- SPID和KPID的区别
- tyvj1114 等差数列