07008 发表于 2016-10-25 10:48:14

python redis使用

#python下redis使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
安装python redis插件:
apt-get install python-redis
编辑python连接redis脚本
vi redis_conn.py
#!/usr/bin/env python
import redis
r=redis.Redis(host='localhost',port=6379,db=0)
#r['yourkey']='yourvalue'
def get_redis(host_ip='localhost',port=6379,db=0):
      return redis.Redis(host=host_ip,port=port,db=db)
         
进入python命令下执行:
>>>import tab
>>>import redis_conn
>>>redis_conn.r.set('key1','value1')
>>>redis_conn.r['key1']='value1'
>>>redis_conn.r.keys()    #查看所有的key
>>>redis_conn.r.delete('key1')    #删除一个key
>>>redis_conn.r.['key1']   #获取key1的value
>>>redis_conn.r.get('key1')



页: [1]
查看完整版本: python redis使用