Manually writing Redis proxy software scripts to implement features like Tweproxy and codes
The content has been implemented as follows:
Up to 1 proxy IP and Port REDISL Client Connection Agent then the script distributes key to the back-end redis through a consistent hash
The script is as follows
Import socketserver,sysfrom threading import threadimport socketfrom hash_ring import hashringredis_servers = [' 127.0.0.1:6480 ', ' 127.0.0.1:6481 ', ' 127.0.0.1:6482 '] ring = hashring (redis_servers) class service (Socketserver.baserequesthandler): def handle (self): data = ' dummy ' print "client connected with ", self.client _address while len (data):        DATA = SELF.REQUEST.RECV (1024x768) if data: &nBsp; key = (Data.split ("\ n")) [4]server = ring.get_node (Key) s = Socket.socket (Socket.af_inet,socket. Sock_stream) s.connect (((Server.split (":")) [0],int ((Server.split (":")) [1]) ) s.sendall (data) r_data = s.recv (1024x768) Print server self.request.send (R_data) print "client exited" self.request.close () Class threadedtcpserver (socketserver.threadingmixin, Socketserver.tcpserver): passtry: t = Threadedtcpserver ((", 6379), service) t.serve_forever () except Keyboardinterrupt: sys.exit (1)
Python proxy functionality similar to Tweproxy and codes features