MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / hashTypeGetValueLength

Function hashTypeGetValueLength

src/t_hash.cpp:150–168  ·  view source on GitHub ↗

Higher level function using hashTypeGet*() to return the length of the * object associated with the requested field, or 0 if the field does not * exist. */

Source from the content-addressed store, hash-verified

148 * object associated with the requested field, or 0 if the field does not
149 * exist. */
150size_t hashTypeGetValueLength(robj_roptr o, const char *field) {
151 size_t len = 0;
152 if (o->encoding == OBJ_ENCODING_ZIPLIST) {
153 const unsigned char *vstr = NULL;
154 unsigned int vlen = UINT_MAX;
155 long long vll = LLONG_MAX;
156
157 if (hashTypeGetFromZiplist(o, field, &vstr, &vlen, &vll) == 0)
158 len = vstr ? vlen : sdigits10(vll);
159 } else if (o->encoding == OBJ_ENCODING_HT) {
160 const char *aux;
161
162 if ((aux = hashTypeGetFromHashTable(o, field)) != NULL)
163 len = sdslen(aux);
164 } else {
165 serverPanic("Unknown hash encoding");
166 }
167 return len;
168}
169
170/* Test if the specified field exists in the given hash. Returns 1 if the field
171 * exists, and 0 when it doesn't. */

Callers 1

hstrlenCommandFunction · 0.85

Calls 4

hashTypeGetFromZiplistFunction · 0.85
sdigits10Function · 0.85
hashTypeGetFromHashTableFunction · 0.85
sdslenFunction · 0.85

Tested by

no test coverage detected