From 22f73b0644c4aa3c86affb468fba33649191176e Mon Sep 17 00:00:00 2001 From: zeekling Date: Wed, 11 Nov 2020 21:01:36 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=85=E8=AF=BBstrlen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/object.c | 5 +++++ src/t_string.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/object.c b/src/object.c index e971ef5..f0542dc 100644 --- a/src/object.c +++ b/src/object.c @@ -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); } } diff --git a/src/t_string.c b/src/t_string.c index c75a40d..6c94a4c 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -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 ||