当前位置:   article > 正文

python操作redis_python读写doris

python读写doris

连接redis库

import redis
r=redis.Redis(
    host="xxx.xx.xx.xx", //ip地址
    password="密码",
    port=6379,
    db=0,
    decode_responses=True#代表默认redis返回自动转字符串类型
)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

str 字符串类型

r.set("token2","4920r2ri3239203ir2",100)  #增加字段或修改,第一个字段为字段名,第二个为字段值,第三个为失效时间
 print(r.get("token2"))#获取字段值
 r.delete("token") #删除字段内容
 result=r.get("token2")
 print(result.decode()) #redis中的值都是字节型,需要decode转换为字符类型
 print(r.exists("token2")) #返回的0和1,0代表不存在,1代表存在
 print(r.type("token2")) #看key的类型
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

hash 哈希类型

r.hset("tqz_s","wxy",'{"id":2,"username":"wxy1"}')
 r.hget("tqz_s","wxy")#获取字段值
 r.hdel("tqz_s","wxy")#删除字段值
 r.hgetall("tq
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/973191
推荐阅读
相关标签
  

闽ICP备14008679号