An error occurred while accessing redis using python on the local machine (windows) today. There are two types of errors: If I configure sentinel, an error such as unknowncommandSENTINEL will be reported; if I configure StrictRedis, NOAUTHAuthenticationrequired will be reported .... an error occurred while accessing redis using python on the local machine (windows) today. There are two types of errors:
If I configure sentinel, an error such as the unknown command 'Sentinel 'will be reported;
If I configure StrictRedis, NOAUTH Authentication required. error will be reported;
Mark it and try to solve it tomorrow ....
Ps: The final result of mongo connection failure is that the password is not set (because the online configuration is regarded as offline configuration ....)
For the first error, the company encountered a problem online recently. the main cause was that sentinel was not started. However, the process was a bit difficult, the company has three redis sentinel machines. after one of them goes down, the other two machines will never be elected as the master, I don't know which temporary worker configures the election machine as 3 when configuring redis. as a result, as long as one of them goes down, the election will fail. In fact, the configuration should be changed to n-m. n indicates the number of machines, and m indicates the number of machines that can be down.
The code for attaching redis is as follows:
import redisimport ConfigParserimport redis.sentinelclass RedisConn: _rp = None def __init__(self): cp = ConfigParser.SafeConfigParser() cp.read('avatar_redis.conf') host = cp.get('redis', 'host') port = cp.get('redis', 'port') db_name = cp.get('redis', 'dbName') pass_word = cp.get('redis', 'passWord') self._rp = redis.StrictRedis(host=host, port=port, db=0, password=pass_word) # = redis.ConnectionPool(host=host, port=port, db=0, password='') #sentinel = redis.sentinel.Sentinel([(host, port)], socket_timeout=0.1) #self._rp = sentinel.master_for(db_name, socket_timeout=0.1) #self._rp = redis.Redis(connection_pool=conn_pool) def get_conn(self): return self._rp def set_value(self, key, value): self._rp.set(key, value) def get_value(self, key): return self._rp.get(key)
For more python-related articles on accessing redis, please follow the PHP Chinese network!