Background description
In a brief description, a shard in the recent project stores data in redis, which should be recommended to users. The front-end receives HTTP requests and parses keys through nginx, the consistent hash algorithm is used to deploy redis in a distributed manner, instead of the master-slave mode. By accessing a group in the redis group, the correct value is read. Usage environment: SuSE redis.2.4.7 hiredis.0.10 g ++ 4.1.2 Problem description if the nginx work process accesses redis in synchronous mode, in high concurrency, it is possible that the current request is not obtained when accessing redis to get the value, or due to other errors, network congestion, and other reasons, resulting in pre-processing congestion in the GET phase, therefore, the processing time will be too long due to a large number of requests. To solve this problem, we will use Asynchronous access to redis. The solution is to try three different asynchronous APIs in the actual environment. The libevent and libev asynchronous APIs are all asynchronously implemented by these two libraries, all these Network Libraries generate threads asynchronously and call the callback function set when the command is executed in advance in response to an event, such as redisasynccontext * AC = .. redisasynccommand (AC, getcallback, inbuffer, "Get % B", key, strlen (key), value, strlen (value); in this case, thread control is not controlled by ourselves, and more third-party libraries will be introduced in the project. Therefore, we decided to use the AE written by the author. c encapsulate this asynchronous access operation. If it is only the next redis.2.4.7, and use the built-in deps/hiredis. Encapsulation cannot be compiled. Some callback interface settings in adapters/AE. h are incorrect. It should be because the author hasn't updated the code for a long time. In hiredis.0.10, some files have been updated recently and are correct. When compiling the self-encapsulated asynchronous Lib, some functions cannot be found during. O compilation. Some files in redis.2.4.7/src/: AE. h AE. c AE _epoll.c config. h zmalloc. h zmalloc. c. Copy these files to the directory of your project to generate them. o file added to the generated libxxx. a. Others: Note that if you use redis when redis-Sever is running. if the timeout parameter in conf is set to 0, connect from the client and sever will not be disabled by the server. If the timeout value is not 0, you need to control the start connect to monitor whether it is valid. If it is invalid, you need to process it. If the connection is closed by the server, you need to set disconnect to recreate the connection. There are other things that I think are described in the document. Here, I have not repeatedly written Author: chlawsdate: