python 通过ssh跳板机链接redis

from sshtunnel import SSHTunnelForwarder
import redis


class Redislocal():



def redistest(self):
server = SSHTunnelForwarder(
ssh_address_or_host='',
ssh_username='root',
ssh_password='',
remote_bind_address=('',6379))

server.start()
try:
r = redis.Redis(host='localhost',port=server.local_bind_port,decode_responses=True,db=2,password="m1i2m3a02")


answer =r.get('phone:vcode:reg:base:17621664327')
print(answer)
return answer
except BaseException as e:
print('出现异常', e)
server.close()



if __name__ == '__main__':
a = Redislocal()

a.redistest()

猜你喜欢

转载自www.cnblogs.com/bibizhou/p/11960089.html