But I tried it myself and found that incr can also specify the increment like incrby, so it feels like there is no difference. The picture below is the result of my test.
The following is the Redis source code. In fact, the underlying implementation of incr and incrBy is consistent, but incrBy needs to do parameter verification
//incr命令
void incrCommand(redisClient *c) {
incrDecrCommand(c,1);
}
//decr命令
void decrCommand(redisClient *c) {
incrDecrCommand(c,-1);
}
//incrBy命令
void incrbyCommand(redisClient *c) {
long long incr;
if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != REDIS_OK) return;
incrDecrCommand(c,incr);
}
//decrby命令
void decrbyCommand(redisClient *c) {
long long incr;
if (getLongLongFromObjectOrReply(c, c->argv[2], &incr, NULL) != REDIS_OK) return;
incrDecrCommand(c,-incr);
}
It can be seen from here that incr does not support numeric parameters.
But why is $redis supported in PHP? Maybe the bottom layer of this library uses the incrBy command of redis
http://redisdoc.com/string/in... http://redisdoc.com/string/in... Is the execution inside redis different? If you use incr to pass parameters, you need to execute the parameter specified times But if you use incrby, you only need to perform one calculation, so you have to confirm it again
After testing, no difference can be seen, the running time is the same, and there is no incr executed multiple times. If the number 23000000000000000000000000000 is executed multiple times, it will definitely take a certain amount of time, but it will take the same time as IncrBys
The following is the Redis source code. In fact, the underlying implementation of incr and incrBy is consistent, but incrBy needs to do parameter verification
It can be seen from here that incr does not support numeric parameters.
But why is $redis supported in PHP? Maybe the bottom layer of this library uses the incrBy command of redis
The source code was posted wrong just now, please modify it
Looking through the source code of the phpredis extension, it should be compatible starting from 2.0.9.
When calling incr, optionally bring a long type number. If the number is not 1, call incrby.
By the way, when using incrBy, if the subsequent parameter is 1, incr will be called.
http://redisdoc.com/string/in...
http://redisdoc.com/string/in...
Is the execution inside redis different? If you use incr to pass parameters, you need to execute the parameter specified times
But if you use incrby, you only need to perform one calculation, so you have to confirm it again
After testing, no difference can be seen, the running time is the same, and there is no incr executed multiple times. If the number 23000000000000000000000000000 is executed multiple times, it will definitely take a certain amount of time, but it will take the same time as IncrBys