首页>>帮助中心>>美国云服务器的python中如何查找redis里的数据

美国云服务器的python中如何查找redis里的数据

2023/8/13 681次

美国云服务器的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

购买使用一诺网络美国云服务器,可以极大降低初创企业、中小企业以及个人开发者等用户群体的整体IT使用成本,无需亲自搭建基础设施、简化了运维和管理的日常工作量,使用户能够更专注于自身的业务发展和创新。美国云服务器低至49/月,购买链接:https://www.enuoidc.com/vpszq.html?typeid=3

版权声明

    声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们996811936@qq.com进行处理。