91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

python中如何查找redis里的數據

小新
1049
2021-04-13 16:01:44
欄目: 云計算

python中查找redis數據的方法:1、打開終端;2、輸入命令創建命令腳本;3、給腳本添加查找redis數據的代碼;4、輸入命令執行腳本連接redis即可。

具體操作步驟如下:

1、打開終端命令行模式。

2、輸入以下命令創建命令腳本。

cat yisu.py #創建腳本

3、在腳本中添加以下連接redis代碼。

import redis

#from rediscluster import StrictRedisCluster

from click._compat import raw_input

from rediscluster import RedisCluster as StrictRedisCluster

def redis_cmd(redis_nodes,isClusterMode=True):

if isinstance(redis_nodes,list):

pass

elif isinstance(redis_nodes,str):

tmp_nodes = []

tmp_tuple = redis_nodes.split(",")

for tt in tmp_tuple:

tt_node = {"host":tt.split(":")[0],"port":tt.split(":")[1]}

tmp_nodes.append(tt_node)

redis_nodes = tmp_nodes

if isClusterMode:

rc = StrictRedisCluster(startup_nodes=redis_nodes, decode_responses=True)

else:

rc = redis.Redis(host=redis_nodes[0]["host"],port=redis_nodes[0]["port"],decode_responses=True)

while True:

s = raw_input("input cmd: >>> ")

if s == "quit" or s == "exit":

print("query end.")

break

cmd = s.split(" ")[0]

key = s.split(" ")[1:]

if cmd.lower() not in ["", "ltrim","ttl", "get", "key", "keys", "set", "lrange", "hget", "smembers", "zrange", "type", "pfcount", "zrange", "hgetall","del", "sismember","sadd","hset","llen","srem","scard","info","cluster info","info Keyspace","hlen","hdel"]:

print ("wrong type of command, please retry...")

elif cmd == "ttl":

print(rc.ttl(*key))

elif cmd == "ltrim":

print(rc.ltrim(*key))

elif cmd == "get":

print(rc.get(*key))

elif cmd == "key":

print(rc.key(*key))

elif cmd == "keys":

print(rc.keys(*key))

elif cmd == "set":

print(rc.set(*key))

elif cmd == "lrange":

print(rc.lrange(*key))

elif cmd == "hget":

print(rc.hget(*key))

elif cmd == "smembers":

print(rc.smembers(*key))

elif cmd == "srem":

print(rc.srem(*key))

elif cmd == "zrange":

print(rc.zrange(*key))

elif cmd == "type":

print(rc.type(*key))

elif cmd == "pfcount":

print(rc.pfcount(*key))

elif cmd == "zrange":

print(rc.zrange(*key))

elif cmd == "hgetall":

print(rc.hgetall(*key))

elif cmd == "del":

print(rc.delete(*key))

elif cmd == "sismember":

print(rc.sismember(*key))

elif cmd == "sadd":

print(rc.sadd(*key))

elif cmd == "scard":

print(rc.scard(*key))

elif cmd == "hset":

print(rc.hset(*key))

elif cmd == "llen":

print(rc.llen(*key))

elif cmd == "hlen":

print(rc.hlen(*key))

elif cmd == "hdel":

print(rc.hdel(*key))

elif cmd == "info":

print(rc.info(*key))

elif cmd == "cluster info":

print(rc.info("cluster"))

elif cmd == "info Keyspace":

print(rc.info("Keyspace"))

def usage():

pass

if __name__=="__main__":

redis_nodes = "172.17.9.106:16388,172.17.9.108:16388"

isRedisCluster = False

4、輸入以下命令執行腳本連接redis即可。

python3 yisu.py

0
凤城市| 绥棱县| 万州区| 南涧| 朝阳区| 尉氏县| 孟村| 庆元县| 蒙城县| 尼勒克县| 南漳县| 襄樊市| 莒南县| 南宫市| 额尔古纳市| 天峨县| 黄骅市| 盐城市| 浦县| 云南省| 嘉荫县| 海门市| 灵宝市| 贺州市| 岳池县| 嘉峪关市| 华宁县| 定安县| 黑水县| 老河口市| 郸城县| 楚雄市| 苍梧县| 江永县| 郑州市| 肇源县| 九寨沟县| 谷城县| 建始县| 乌恰县| 慈利县|