mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 00:52:38 +00:00
faster INCR doing far less allocation in common cases
This commit is contained in:
parent
dd48de748c
commit
b215a496a4
@ -144,8 +144,23 @@ void incrDecrCommand(redisClient *c, long long incr) {
|
||||
|
||||
o = lookupKeyWrite(c->db,c->argv[1]);
|
||||
if (o != NULL && checkType(c,o,REDIS_STRING)) return;
|
||||
if (getLongLongFromObjectOrReply(c,o,&value,NULL) != REDIS_OK) return;
|
||||
|
||||
/* Fast path if the object is integer encoded and is not shared. */
|
||||
if (o && o->refcount == 1 && o->encoding == REDIS_ENCODING_INT) {
|
||||
long long newval = ((long)o->ptr) + incr;
|
||||
|
||||
if (newval >= LONG_MIN && newval <= LONG_MAX) {
|
||||
o->ptr = (void*) (long) newval;
|
||||
touchWatchedKey(c->db,c->argv[1]);
|
||||
server.dirty++;
|
||||
addReplyLongLong(c,newval);
|
||||
return;
|
||||
}
|
||||
/* ... else take the usual safe path */
|
||||
}
|
||||
|
||||
/* Otherwise we create a new object and replace the old one. */
|
||||
if (getLongLongFromObjectOrReply(c,o,&value,NULL) != REDIS_OK) return;
|
||||
value += incr;
|
||||
o = createStringObjectFromLongLong(value);
|
||||
dbReplace(c->db,c->argv[1],o);
|
||||
|
Loading…
Reference in New Issue
Block a user