码迷,mamicode.com
首页 > 其他好文 > 详细

redis 的简单用法

时间:2018-11-25 21:15:51      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:response   无法   技术分享   res   print   iter   python   安装   www.   

 

使用  :下载完后 打开任务管理器 把redis_server 进程关掉,

  切换到   E:\redis 中 

    redis-server.exe redis.windows.conf

打开一个 cmd 窗口 使用 cd 命令切换目录到 C:\redis 运行:

redis-server.exe redis.windows.conf

如果想方便的话,可以把 redis 的路径加到系统的环境变量里,这样就省得再输路径了,后面的那个 redis.windows.conf 可以省略,如果省略,会启用默认的。输入之后,会显示如下界面:

技术分享图片

这时候另启一个 cmd 窗口,原来的不要关闭,不然就无法访问服务端了。

 

 

redis 在python中的使用

单独建立py文件

 

import redis
#连接池
POOL = redis.ConnectionPool(host="127.0.0.1", port=6379, decode_responses=True)

其他文件导入用法
REDIS_CONN=redis.Redis(connection_pool=POOL)


几个常用指令
conn=redis.Redis(connection_pool=POOL)
conn.set(‘xx‘,‘oo‘) #set
print(conn.get(‘xx‘)) #get
conn.hset(‘xxxxx‘,‘ooo‘,‘qq‘) #hset
print(conn.hget(‘xxxxx‘, ‘ooo‘)) #hget
conn.hmset(‘nnn‘,{‘aaa‘:"{‘xx‘,‘oo‘}",‘bbb‘:‘kkk‘}) #hmset
print((conn.hgetall(‘nnn‘,))) #hgetall

REDIS_CONN.scan_iter(shopping_car_key)  #.scan_iter  模糊匹配
if not REDIS_CONN.exists(shopping_car_key):   #.exists #判断是否有  返回为布尔值
REDIS_CONN.delete(shopping_car_keys) #.delete  删除




 

redis 的简单用法

标签:response   无法   技术分享   res   print   iter   python   安装   www.   

原文地址:https://www.cnblogs.com/xdlzs/p/10017339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!