import redis pool = redis.ConnectionPool(host='localhost', port=6379,encoding="UTF-8",decode_responses=True) r = redis.Redis(connection_pool=pool) result = r.keys("*") #遍历所有元素 for res in result: print(res) #查看长度 print(len(result))