Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
d8f8b057
Commit
d8f8b057
authored
Feb 27, 2015
by
antirez
Browse files
Hash: API to get value string len by field name.
parent
c9550788
Changes
1
Show whitespace changes
Inline
Side-by-side
src/t_hash.c
View file @
d8f8b057
...
@@ -130,7 +130,6 @@ robj *hashTypeGetObject(robj *o, robj *field) {
...
@@ -130,7 +130,6 @@ robj *hashTypeGetObject(robj *o, robj *field) {
value
=
createStringObjectFromLongLong
(
vll
);
value
=
createStringObjectFromLongLong
(
vll
);
}
}
}
}
}
else
if
(
o
->
encoding
==
REDIS_ENCODING_HT
)
{
}
else
if
(
o
->
encoding
==
REDIS_ENCODING_HT
)
{
robj
*
aux
;
robj
*
aux
;
...
@@ -144,6 +143,29 @@ robj *hashTypeGetObject(robj *o, robj *field) {
...
@@ -144,6 +143,29 @@ robj *hashTypeGetObject(robj *o, robj *field) {
return
value
;
return
value
;
}
}
/* 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. */
size_t
hashTypeGetValueLength
(
robj
*
o
,
robj
*
field
)
{
size_t
len
=
0
;
if
(
o
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
unsigned
char
*
vstr
=
NULL
;
unsigned
int
vlen
=
UINT_MAX
;
long
long
vll
=
LLONG_MAX
;
if
(
hashTypeGetFromZiplist
(
o
,
field
,
&
vstr
,
&
vlen
,
&
vll
)
==
0
)
len
=
vstr
?
vlen
:
sdigits10
(
vll
);
}
else
if
(
o
->
encoding
==
REDIS_ENCODING_HT
)
{
robj
*
aux
;
if
(
hashTypeGetFromHashTable
(
o
,
field
,
&
aux
)
==
0
)
len
=
sdslen
(
aux
->
ptr
);
}
else
{
redisPanic
(
"Unknown hash encoding"
);
}
return
len
;
}
/* Test if the specified field exists in the given hash. Returns 1 if the field
/* Test if the specified field exists in the given hash. Returns 1 if the field
* exists, and 0 when it doesn't. */
* exists, and 0 when it doesn't. */
int
hashTypeExists
(
robj
*
o
,
robj
*
field
)
{
int
hashTypeExists
(
robj
*
o
,
robj
*
field
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment