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
0b10e104
Commit
0b10e104
authored
Mar 08, 2011
by
Pieter Noordhuis
Browse files
Support dual encoding in ZREM
parent
3ca7532a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/t_zset.c
View file @
0b10e104
...
@@ -449,6 +449,11 @@ int zzlCompareElements(unsigned char *eptr, unsigned char *cstr, unsigned int cl
...
@@ -449,6 +449,11 @@ int zzlCompareElements(unsigned char *eptr, unsigned char *cstr, unsigned int cl
return
cmp
;
return
cmp
;
}
}
unsigned
int
*
zzlLength
(
robj
*
zobj
)
{
unsigned
char
*
zl
=
zobj
->
ptr
;
return
ziplistLen
(
zl
)
/
2
;
}
unsigned
char
*
zzlFind
(
robj
*
zobj
,
robj
*
ele
,
double
*
score
)
{
unsigned
char
*
zzlFind
(
robj
*
zobj
,
robj
*
ele
,
double
*
score
)
{
unsigned
char
*
zl
=
zobj
->
ptr
;
unsigned
char
*
zl
=
zobj
->
ptr
;
unsigned
char
*
eptr
=
ziplistIndex
(
zl
,
0
),
*
sptr
;
unsigned
char
*
eptr
=
ziplistIndex
(
zl
,
0
),
*
sptr
;
...
@@ -460,7 +465,7 @@ unsigned char *zzlFind(robj *zobj, robj *ele, double *score) {
...
@@ -460,7 +465,7 @@ unsigned char *zzlFind(robj *zobj, robj *ele, double *score) {
if
(
ziplistCompare
(
eptr
,
ele
->
ptr
,
sdslen
(
ele
->
ptr
)))
{
if
(
ziplistCompare
(
eptr
,
ele
->
ptr
,
sdslen
(
ele
->
ptr
)))
{
/* Matching element, pull out score. */
/* Matching element, pull out score. */
*
score
=
zzlGetScore
(
sptr
);
if
(
score
!=
NULL
)
*
score
=
zzlGetScore
(
sptr
);
decrRefCount
(
ele
);
decrRefCount
(
ele
);
return
eptr
;
return
eptr
;
}
}
...
@@ -688,32 +693,47 @@ void zincrbyCommand(redisClient *c) {
...
@@ -688,32 +693,47 @@ void zincrbyCommand(redisClient *c) {
}
}
void
zremCommand
(
redisClient
*
c
)
{
void
zremCommand
(
redisClient
*
c
)
{
robj
*
zsetobj
;
robj
*
key
=
c
->
argv
[
1
];
zset
*
zs
;
robj
*
ele
=
c
->
argv
[
2
];
dictEntry
*
de
;
robj
*
zobj
;
double
curscore
;
int
deleted
;
if
((
z
set
obj
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
]
,
shared
.
czero
))
==
NULL
||
if
((
zobj
=
lookupKeyWriteOrReply
(
c
,
key
,
shared
.
czero
))
==
NULL
||
checkType
(
c
,
z
set
obj
,
REDIS_ZSET
))
return
;
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
zs
=
zsetobj
->
ptr
;
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
unsigned
char
*
eptr
;
de
=
dictFind
(
zs
->
dict
,
c
->
argv
[
2
]);
if
(
de
==
NULL
)
{
if
((
eptr
=
zzlFind
(
zobj
,
ele
,
NULL
))
!=
NULL
)
{
addReply
(
c
,
shared
.
czero
);
redisAssert
(
zzlDelete
(
zobj
,
eptr
)
==
REDIS_OK
);
return
;
if
(
zzlLength
(
zobj
)
==
0
)
dbDelete
(
c
->
db
,
key
);
}
else
{
addReply
(
c
,
shared
.
czero
);
return
;
}
}
else
if
(
zobj
->
encoding
==
REDIS_ENCODING_RAW
)
{
zset
*
zs
=
zobj
->
ptr
;
dictEntry
*
de
;
double
score
;
de
=
dictFind
(
zs
->
dict
,
ele
);
if
(
de
!=
NULL
)
{
/* Delete from the skiplist */
score
=
*
(
double
*
)
dictGetEntryVal
(
de
);
redisAssert
(
zslDelete
(
zs
->
zsl
,
score
,
ele
));
/* Delete from the hash table */
dictDelete
(
zs
->
dict
,
ele
);
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
if
(
dictSize
(
zs
->
dict
)
==
0
)
dbDelete
(
c
->
db
,
key
);
}
else
{
addReply
(
c
,
shared
.
czero
);
return
;
}
}
else
{
redisPanic
(
"Unknown sorted set encoding"
);
}
}
/* Delete from the skiplist */
curscore
=
*
(
double
*
)
dictGetEntryVal
(
de
);
deleted
=
zslDelete
(
zs
->
zsl
,
curscore
,
c
->
argv
[
2
]);
redisAssert
(
deleted
!=
0
);
/* Delete from the hash table */
signalModifiedKey
(
c
->
db
,
key
);
dictDelete
(
zs
->
dict
,
c
->
argv
[
2
]);
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
if
(
dictSize
(
zs
->
dict
)
==
0
)
dbDelete
(
c
->
db
,
c
->
argv
[
1
]);
signalModifiedKey
(
c
->
db
,
c
->
argv
[
1
]);
server
.
dirty
++
;
server
.
dirty
++
;
addReply
(
c
,
shared
.
cone
);
addReply
(
c
,
shared
.
cone
);
}
}
...
...
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