Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
dda0f37f
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dda0f37f
编写于
4月 15, 2016
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ZREM refactored into proper API.
上级
6f926c3e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
49 deletion
+48
-49
src/server.h
src/server.h
+1
-0
src/t_zset.c
src/t_zset.c
+47
-49
未找到文件。
src/server.h
浏览文件 @
dda0f37f
...
...
@@ -1332,6 +1332,7 @@ int zsetScore(robj *zobj, sds member, double *score);
unsigned
long
zslGetRank
(
zskiplist
*
zsl
,
double
score
,
sds
o
);
int
zsetAdd
(
robj
*
zobj
,
double
score
,
sds
ele
,
int
*
flags
,
double
*
newscore
);
long
zsetRank
(
robj
*
zobj
,
sds
ele
,
int
reverse
);
int
zsetDel
(
robj
*
zobj
,
sds
ele
);
/* Core functions */
int
freeMemoryIfNeeded
(
void
);
...
...
src/t_zset.c
浏览文件 @
dda0f37f
...
...
@@ -1370,6 +1370,47 @@ int zsetAdd(robj *zobj, double score, sds ele, int *flags, double *newscore) {
return
0
;
/* Never reached. */
}
/* Delete the element 'ele' from the sorted set, returning 1 if the element
* existed and was deleted, 0 otherwise (the element was not there). */
int
zsetDel
(
robj
*
zobj
,
sds
ele
)
{
if
(
zobj
->
encoding
==
OBJ_ENCODING_ZIPLIST
)
{
unsigned
char
*
eptr
;
if
((
eptr
=
zzlFind
(
zobj
->
ptr
,
ele
,
NULL
))
!=
NULL
)
{
zobj
->
ptr
=
zzlDelete
(
zobj
->
ptr
,
eptr
);
return
1
;
}
}
else
if
(
zobj
->
encoding
==
OBJ_ENCODING_SKIPLIST
)
{
zset
*
zs
=
zobj
->
ptr
;
dictEntry
*
de
;
double
score
;
de
=
dictFind
(
zs
->
dict
,
ele
);
if
(
de
!=
NULL
)
{
/* Get the score in order to delete from the skiplist later. */
score
=
*
(
double
*
)
dictGetVal
(
de
);
/* Delete from the hash table and later from the skiplist.
* Note that the order is important: deleting from the skiplist
* actually releases the SDS string representing the element,
* which is shared between the skiplist and the hash table, so
* we need to delete from the skiplist as the final step. */
int
retval1
=
dictDelete
(
zs
->
dict
,
ele
);
/* Delete from skiplist. */
int
retval2
=
zslDelete
(
zs
->
zsl
,
score
,
ele
,
NULL
);
serverAssert
(
retval1
==
DICT_OK
&&
retval2
);
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
return
1
;
}
}
else
{
serverPanic
(
"Unknown sorted set encoding"
);
}
return
0
;
/* No such element found. */
}
/* Given a sorted set object returns the 0-based rank of the object or
* -1 if the object does not exist.
*
...
...
@@ -1579,56 +1620,13 @@ void zremCommand(client *c) {
if
((
zobj
=
lookupKeyWriteOrReply
(
c
,
key
,
shared
.
czero
))
==
NULL
||
checkType
(
c
,
zobj
,
OBJ_ZSET
))
return
;
if
(
zobj
->
encoding
==
OBJ_ENCODING_ZIPLIST
)
{
unsigned
char
*
eptr
;
for
(
j
=
2
;
j
<
c
->
argc
;
j
++
)
{
if
((
eptr
=
zzlFind
(
zobj
->
ptr
,
c
->
argv
[
j
]
->
ptr
,
NULL
))
!=
NULL
)
{
deleted
++
;
zobj
->
ptr
=
zzlDelete
(
zobj
->
ptr
,
eptr
);
if
(
zzlLength
(
zobj
->
ptr
)
==
0
)
{
dbDelete
(
c
->
db
,
key
);
keyremoved
=
1
;
break
;
}
}
}
}
else
if
(
zobj
->
encoding
==
OBJ_ENCODING_SKIPLIST
)
{
zset
*
zs
=
zobj
->
ptr
;
dictEntry
*
de
;
double
score
;
for
(
j
=
2
;
j
<
c
->
argc
;
j
++
)
{
de
=
dictFind
(
zs
->
dict
,
c
->
argv
[
j
]
->
ptr
);
if
(
de
!=
NULL
)
{
deleted
++
;
/* Get the score in order to delete from the skiplist later. */
score
=
*
(
double
*
)
dictGetVal
(
de
);
/* Delete from the hash table and later from the skiplist.
* Note that the order is important: deleting from the skiplist
* actually releases the SDS string representing the element,
* which is shared between the skiplist and the hash table, so
* we need to delete from the skiplist as the final step. */
int
retval1
=
dictDelete
(
zs
->
dict
,
c
->
argv
[
j
]
->
ptr
);
/* Delete from skiplist. */
int
retval2
=
zslDelete
(
zs
->
zsl
,
score
,
c
->
argv
[
j
]
->
ptr
,
NULL
);
serverAssertWithInfo
(
c
,
c
->
argv
[
j
],
retval1
==
DICT_OK
&&
retval2
);
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
if
(
dictSize
(
zs
->
dict
)
==
0
)
{
dbDelete
(
c
->
db
,
key
);
keyremoved
=
1
;
break
;
}
}
for
(
j
=
2
;
j
<
c
->
argc
;
j
++
)
{
if
(
zsetDel
(
zobj
,
c
->
argv
[
j
]
->
ptr
))
deleted
++
;
if
(
zsetLength
(
zobj
)
==
0
)
{
dbDelete
(
c
->
db
,
key
);
keyremoved
=
1
;
break
;
}
}
else
{
serverPanic
(
"Unknown sorted set encoding"
);
}
if
(
deleted
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录