zoukankan      html  css  js  c++  java
  • python redis demo

    上代码,redis-demo

     1 #!/usr/bin/env python
     2 #_*_ coding:UTF-8 _*_
     3 
     4 import redis
     5 
     6 
     7 ####配置参数
     8 host = '192.168.0.12'
     9 port = 16000
    10 password = 'wrfg6OTNaXTqd96H7TK7bYIV'
    11 
    12 
    13 ####
    14 #连接redis
    15 #单个值的
    16 def redis_conn(host,port,password,db,key,act="get",value=''):
    17     r = redis.StrictRedis(host=host, port=port, password=password, db=db, decode_responses=False)
    18 
    19     #判断key类型
    20     s = r.type(key)
    21     print('type of key: %s'%s)
    22 
    23     #设置key
    24     if act=="set":
    25             r.set(key,value)
    26             print('已经set完,db%s,key=%s,值为 %s'%(db,key,value))
    27             return value
    28 
    29     if r.exists(key):
    30         #查询
    31         if act=="get":
    32             # 取key值
    33             value=r.get(key)
    34             print('正在查询db%s,key=%s 
     value=%s'%(db,key,value))
    35             return value
    36 
    37         #删除
    38         elif act=="del":
    39             # 取key值
    40             value=r.get(key)
    41             r.delete(key)
    42             print('已经删除,db%s,key=%s,
    值为 %s'%(db,key,value))
    43             return  
    44     else:
    45         print('key 不存在')
    46 
    47 
    48 key="old_user_pop_win_count_20190910_22"
    49 db=2
    50 #调用函数,get
    51 result=redis_conn(host,port,password,db,key,act="get")
    52 print('result:',result)
    53 
    54 #del
    55 result=redis_conn(host,port,password,db,key,act="del")
    56 print('result:',result)
    57 
    58 
    59 #set
    60 db=1
    61 key="age"
    62 result=redis_conn(host,port,password,db,key,act="set",value="88")
  • 相关阅读:
    SpringBoot整合系列-整合H2
    SpringBoot整合系列-整合Swagger2
    BZOJ3626 [LNOI2014]LCA
    BZOJ4475 [Jsoi2015]子集选取
    BZOJ4466 [Jsoi2013]超立方体
    BZOJ3997 [TJOI2015]组合数学
    BZOJ3996 [TJOI2015]线性代数
    BZOJ2227 [Zjoi2011]看电影(movie)
    BZOJ2337 [HNOI2011]XOR和路径
    BZOJ2330 [SCOI2011]糖果
  • 原文地址:https://www.cnblogs.com/lisa2016/p/11499100.html
Copyright © 2011-2022 走看看