加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python 操作redis

发布时间:2020-12-20 10:54:04 所属栏目:Python 来源:网络整理
导读:from redis_db import poolimport redisimport timecon = 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) #
from redis_db import poolimport redisimport timecon = 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",-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",-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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读