#!/usr/bin/python# Coding=utf-8__author__= ' Shuangjiang 'ImportRedisImportsysdefault_encoding= ' Utf-8 'ifSys.getdefaultencoding ()! =default_encoding:reload (SYS) sys.setdefaultencoding (default_encoding)classmyredis:def __init__ (self,host,port,db_index): Self._redis_host=host Self._redis_port=Port self._redis_db=Db_index def Getredis (self): _redis= Redis. Redis (Host=self._redis_host, Port=self._redis_port, db=self._redis_db)return_redisdef Getrecredis (): Host= ' 127.0.0.1 'Port= 6379Db_index= 0returnMyredis (Host,port,db_index). Getredis () def Getqueueredis (): Host= ' 172.0.0.1 'Port= 6379Db_index= 0returnMyredis (Host,port,db_index). Getredis ()
Import directly at the point of invocation:
From Common.myredis Import *
Use:
Get Redis object: _redis = Getqueueredis ()
Use: Value = _redis.rpop (' Hello ')
Python Connect Redis Tool class