阿尔哦覅和 发表于 2018-8-16 12:26:05

python redis使用

  
安装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使用