阅读strlen

This commit is contained in:
LingZhaoHui 2020-11-11 21:01:36 +08:00
parent a335044204
commit 22f73b0644
2 changed files with 8 additions and 0 deletions

View File

@ -611,11 +611,16 @@ int equalStringObjects(robj *a, robj *b) {
}
}
/**
* value的长度
* */
size_t stringObjectLen(robj *o) {
serverAssertWithInfo(NULL,o,o->type == OBJ_STRING);
if (sdsEncodedObject(o)) {
// 对于字符串类型使用sdslen计算
return sdslen(o->ptr);
} else {
// 对于非字符串使用
return sdigits10((long)o->ptr);
}
}

View File

@ -495,6 +495,9 @@ void appendCommand(client *c) {
addReplyLongLong(c,totlen);
}
/**
* strlen
* */
void strlenCommand(client *c) {
robj *o;
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||