redis python 出错重连_python 操作redis

from redis_db import pool

import redis

import time

con = redis.Redis(

connection_pool=pool

)

try:

# 字符串

# con.set("country", "英国")

# con.set("city", "伦敦")

# # city = con.get("city").decode("utf-8")

# con.expire("city", 5)

# time.sleep(6)

# city = con.get("city").decode("utf-8")

# print(city)

# 字符串

# con.delete("country","city")

# con.mset({"country":"德国","city":"柏林"})

# result = con.mget("country",'city')

# for one in result:

# print(one.decode("utf-8"))

# 列表

# con.delete("dname")

# con.rpush("dname","董事会","秘书处","财务部","技术部")

# con.lpop("dname")

# result = con.lrange("dname", 0, -1)

# for one in result:

# print(one.decode("utf-8"))

# 无序集合

# con.delete("employee")

# con.sadd("employee",8001,8002,8003)

# con.srem("employee",8001)

# result = con.smembers("employee")

# for one in result:

# print(one.decode("utf-8"))

#

# # 有序集合

# con.delete("keyword")

# con.zadd("keyword",{"马云":0,"张朝阳":0,"丁磊":0})

# con.zincrby("keyword", "10","马云")

# result = con.zrevrange("keyword", 0, -1)

# for one in result:

# print(one.decode("utf-8"))

# 哈希

# con.hmset("9527",{"name":"Scott","sex":"male","age":"35"})

# con.hset("9527","city","纽约")

#

# # con.hdel("9527","age")

# exists = con.hexists("9527","name")

# # print(exists) True

#

# result = con.hgetall("9527")

# for one in result:

# print(one.decode("utf-8"),result[one].decode("utf-8"))

# 事务

# pipline = con.pipeline()

# pipline.watch("9527")

# pipline.multi()

#

# pipline.hset("9527","name","Jack")

# pipline.hset("9527","age",23)

#

# pipline.execute()

except Exception as e:

print(e)

finally:

if "pipline" in dir():

pipline.reset()

del con

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值