Python access to redis

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.