zoukankan      html  css  js  c++  java
  • Python scan查找Redis集群中的key

    
    
    import redis
    import sys
    from rediscluster import StrictRedisCluster
    #host = "172.17.155.118"
    #port = 6379
    #passwd = ""
    instance_ip = sys.argv[1]
    instance_port = sys.argv[2]
    startup_nodes = [{"host": instance_ip, "port": instance_port }]
    rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True, password="")
    def check_key(rc,k):
        key_len = 0
        big_key = []
        try:
            type = rc.type(k)
            if type == "string":
                key_len = rc.strlen(k)
            elif type == "hash":
                key_len = rc.hlen(k)
            elif type == "list":
                key_len = rc.llen(k)
            elif type == "set":
                key_len = rc.scard(k)
            elif type == "zset":
                key_len = rc.zcard(k)
            else:
                print("Redis key type: "+type)
        except Exception:
            print("Redis key type error.")
        if key_len > 5:
            big_key.append(k)
            big_key.append(type)
            big_key.append(key_len)
            print(big_key)
    
    def scan_key(rc):
        rc_end = []
        try:
            rc_end = rc.scan_iter("*")
        except Exception as e:
            pass
            #print(e)
        for k in rc_end:
            check_key(rc,k)
    
    if __name__ == '__main__':
        scan_key(rc)
    
    
    
     
    import redis
    import sys
    
    db_host = ""
    db_port = 
    r = redis.StrictRedis(host=db_host, port=int(db_port))
    for k in r.scan_iter("lie*"):
        print k
  • 相关阅读:
    马哥Linux——第三周作业
    [laravel]phpunit
    [laravel]要点
    [laravel]请求处理
    [angularJS]ng-hide|ng-show切换
    [yii2]urlmanger
    虚拟机bridged, NAT and host-only网络区别
    [yii]Fetch data from database and create listbox in yii
    [shell test] multiple conditions
    特殊的shell变量:
  • 原文地址:https://www.cnblogs.com/lwhctv/p/10841298.html
Copyright © 2011-2022 走看看