A large number of zincrby commands are used in the project because the Count value of an indicator in the log needs to be counted and the topn needs to be returned in order.
Normally, zincrby (zincrby default: Type 1 typea) can work normally.
The actual situation is that the log generation is too fast, redis CPU utilization is often 100%, and data is also lost.
Can I increase the cumulative value of multiple indicators at a time, for example, zincrby default: Type 1 typea 1 typeB 1 typec ..., in this way, compressing multiple communications into one communication will certainly improve the processing capability.
Zincrby only supports four parameters. It is clearly written in the official redis documentation:
Zincrby key increment member, so I thought of modifying the redis (2.4.17) source code to implement my own functions. Open the redis. C source code file and go to the command table supported by redis. Part of the content is as follows: struct rediscommand readonlycommandtable [] = {
{"Get", getcommand, 2, 0, null, 1, 1 },
{"Set", setcommand, 3, redis_assist_denyoom, null, 0 },
{"Setnx", setnxcommand, 3, redis_assist_denyoom, null, 0, 0 },
{"Setex", setexcommand, 4, redis_assist_denyoom, null, 0 },
{"APPEND", appendcommand, 3, redis_assist_denyoom, null, 1 },
{"Strlen", strlencommand, 2, 0, null, 1, 1 },
... {"Zincrby", zincrbycommand, 4, redis_assist_denyoom, null, 1}
}
The command parameters in this version are different from those in version 2.6 and later, but the first few parameters are the same. The first parameter indicates the command keyword, the second parameter indicates the function name, and the third parameter indicates the number of input parameters, A positive number indicates that the number of parameters can only be equal to, and a negative number indicates that the number of parameters must be at least equal. Because the zincrby command specifies the parameter 4, after reading the subsequent implementation code, it is found that when the parameter is greater than 4, it is also processed, so change 4 to-4, and then make, test. {"Zincrby", zincrbycommand,-4, redis_assist_denyoom, null, 1}
Run the following command:
In fact, the source code modification is very simple, and a parameter is modified. The other parameters are not dynamic, which is much different from the original one, but the goal is achieved.