阅读strlen
This commit is contained in:
parent
a335044204
commit
22f73b0644
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 ||
|
||||
|
Loading…
Reference in New Issue
Block a user