import redis import sys import time import random def get_bf_bigkeys(): try: redis_conn = redis.StrictRedis(host='127.0.0.1', port=8001, db=0, password='******') except: print("connect redis error") sys.exit(1) dict_key = {} cursor = 1 while cursor != 0: if cursor == 1: key = redis_conn.scan(cursor=0, match='*', count=5000) else: key = redis_conn.scan(cursor=cursor,match='*', count=5000) cursor = key[0] if len(key[1]) > 0: for var in key[1]: if str(redis_conn.type(var), encoding = "utf-8") == 'MBbloom--': info = redis_conn.debug_object(var) dict_key[var] = float(info['serializedlength']) / 1024 / 1024 # byte ---> mb res = sorted(dict_key.items(), key=lambda dict_key: dict_key[1], reverse=True) for i in range(10 if len(res) > 10 else len(res)): print(res[i]) if __name__ == "__main__": get_bf_bigkeys()
统计结果示例如下
[root@tencent02 redis8001]# python3 static_big_bf_keys.py (b'bloom_filter_test', 4.000059127807617) (b'my_bf2', 0.04577445983886719) (b'bloom_filter_test2', 0.00014019012451171875) (b'my_bf1', 0.0001220703125) [root@tencent02 redis8001]#