Modify redis source code with the zincrby and hincrby commands

Source: Internet
Author: User

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.

Related Article

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.