Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
628b9fa5
Commit
628b9fa5
authored
Apr 03, 2014
by
antirez
Browse files
Remove HyperLogLog type checking duplicated code.
parent
aecb59b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/hyperloglog.c
View file @
628b9fa5
...
...
@@ -456,6 +456,23 @@ robj *createHLLObject(void) {
return
o
;
}
/* Check if the object is a String of REDIS_HLL_SIZE bytes.
* Return REDIS_OK if this is true, otherwise reply to the client
* with an error and return REDIS_ERR. */
int
isHLLObjectOrReply
(
redisClient
*
c
,
robj
*
o
)
{
/* Key exists, check type */
if
(
checkType
(
c
,
o
,
REDIS_STRING
))
return
REDIS_ERR
;
/* Error already sent. */
/* If this is a string representing an HLL, the size should match
* exactly. */
if
(
stringObjectLen
(
o
)
!=
REDIS_HLL_SIZE
)
{
addReplyErrorFormat
(
c
,
"Key is not a valid HyperLogLog string value."
);
return
REDIS_ERR
;
}
return
REDIS_OK
;
}
/* PFADD var ele ele ele ... ele => :0 or :1 */
void
pfaddCommand
(
redisClient
*
c
)
{
robj
*
o
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
1
]);
...
...
@@ -470,18 +487,7 @@ void pfaddCommand(redisClient *c) {
dbAdd
(
c
->
db
,
c
->
argv
[
1
],
o
);
updated
++
;
}
else
{
/* Key exists, check type */
if
(
checkType
(
c
,
o
,
REDIS_STRING
))
return
;
/* If this is a string representing an HLL, the size should match
* exactly. */
if
(
stringObjectLen
(
o
)
!=
REDIS_HLL_SIZE
)
{
addReplyErrorFormat
(
c
,
"PFADD target key must contain a %d bytes string."
,
REDIS_HLL_SIZE
);
return
;
}
if
(
isHLLObjectOrReply
(
c
,
o
)
!=
REDIS_OK
)
return
;
o
=
dbUnshareStringValue
(
c
->
db
,
c
->
argv
[
1
],
o
);
}
/* Perform the low level ADD operation for every element. */
...
...
@@ -514,18 +520,7 @@ void pfcountCommand(redisClient *c) {
* we would have a key as HLLADD creates it as a side effect. */
addReply
(
c
,
shared
.
czero
);
}
else
{
/* Key exists, check type */
if
(
checkType
(
c
,
o
,
REDIS_STRING
))
return
;
/* If this is a string representing an HLL, the size should match
* exactly. */
if
(
stringObjectLen
(
o
)
!=
REDIS_HLL_SIZE
)
{
addReplyErrorFormat
(
c
,
"PFCOUNT target key must contain a %d bytes string."
,
REDIS_HLL_SIZE
);
return
;
}
if
(
isHLLObjectOrReply
(
c
,
o
)
!=
REDIS_OK
)
return
;
/* Check if the cached cardinality is valid. */
registers
=
o
->
ptr
;
...
...
@@ -580,15 +575,7 @@ void pfmergeCommand(redisClient *c) {
/* Check type and size. */
robj
*
o
=
lookupKeyRead
(
c
->
db
,
c
->
argv
[
j
]);
if
(
o
==
NULL
)
continue
;
/* Assume empty HLL for non existing var. */
if
(
checkType
(
c
,
o
,
REDIS_STRING
))
return
;
if
(
stringObjectLen
(
o
)
!=
REDIS_HLL_SIZE
)
{
addReplyErrorFormat
(
c
,
"PFADD target key must contain a %d bytes string."
,
REDIS_HLL_SIZE
);
return
;
}
if
(
isHLLObjectOrReply
(
c
,
o
)
!=
REDIS_OK
)
return
;
/* Merge with this HLL with our 'max' HHL by setting max[i]
* to MAX(max[i],hll[i]). */
...
...
@@ -716,18 +703,7 @@ void pfgetregCommand(redisClient *c) {
addReplyError
(
c
,
"The specified key does not exist"
);
return
;
}
else
{
/* Key exists, check type */
if
(
checkType
(
c
,
o
,
REDIS_STRING
))
return
;
/* If this is a string representing an HLL, the size should match
* exactly. */
if
(
stringObjectLen
(
o
)
!=
REDIS_HLL_SIZE
)
{
addReplyErrorFormat
(
c
,
"PFCOUNT target key must contain a %d bytes string."
,
REDIS_HLL_SIZE
);
return
;
}
if
(
isHLLObjectOrReply
(
c
,
o
)
!=
REDIS_OK
)
return
;
registers
=
o
->
ptr
;
addReplyMultiBulkLen
(
c
,
REDIS_HLL_REGISTERS
);
...
...
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