Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
f4f56e1d
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
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,发现更多精彩内容 >>
提交
f4f56e1d
编写于
5月 17, 2009
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SDIFF/SDIFFSTORE implemnted unifying it with the implementation of SUNION/SUNIONSTORE
上级
1904ecc1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
65 addition
and
18 deletion
+65
-18
redis-cli.c
redis-cli.c
+2
-0
redis.c
redis.c
+46
-18
test-redis.tcl
test-redis.tcl
+17
-0
未找到文件。
redis-cli.c
浏览文件 @
f4f56e1d
...
@@ -83,6 +83,8 @@ static struct redisCommand cmdTable[] = {
...
@@ -83,6 +83,8 @@ static struct redisCommand cmdTable[] = {
{
"sinterstore"
,
-
3
,
REDIS_CMD_INLINE
},
{
"sinterstore"
,
-
3
,
REDIS_CMD_INLINE
},
{
"sunion"
,
-
2
,
REDIS_CMD_INLINE
},
{
"sunion"
,
-
2
,
REDIS_CMD_INLINE
},
{
"sunionstore"
,
-
3
,
REDIS_CMD_INLINE
},
{
"sunionstore"
,
-
3
,
REDIS_CMD_INLINE
},
{
"sdiff"
,
-
2
,
REDIS_CMD_INLINE
},
{
"sdiffstore"
,
-
3
,
REDIS_CMD_INLINE
},
{
"smembers"
,
2
,
REDIS_CMD_INLINE
},
{
"smembers"
,
2
,
REDIS_CMD_INLINE
},
{
"incrby"
,
3
,
REDIS_CMD_INLINE
},
{
"incrby"
,
3
,
REDIS_CMD_INLINE
},
{
"decrby"
,
3
,
REDIS_CMD_INLINE
},
{
"decrby"
,
3
,
REDIS_CMD_INLINE
},
...
...
redis.c
浏览文件 @
f4f56e1d
...
@@ -348,6 +348,8 @@ static void sinterCommand(redisClient *c);
...
@@ -348,6 +348,8 @@ static void sinterCommand(redisClient *c);
static
void
sinterstoreCommand
(
redisClient
*
c
);
static
void
sinterstoreCommand
(
redisClient
*
c
);
static
void
sunionCommand
(
redisClient
*
c
);
static
void
sunionCommand
(
redisClient
*
c
);
static
void
sunionstoreCommand
(
redisClient
*
c
);
static
void
sunionstoreCommand
(
redisClient
*
c
);
static
void
sdiffCommand
(
redisClient
*
c
);
static
void
sdiffstoreCommand
(
redisClient
*
c
);
static
void
syncCommand
(
redisClient
*
c
);
static
void
syncCommand
(
redisClient
*
c
);
static
void
flushdbCommand
(
redisClient
*
c
);
static
void
flushdbCommand
(
redisClient
*
c
);
static
void
flushallCommand
(
redisClient
*
c
);
static
void
flushallCommand
(
redisClient
*
c
);
...
@@ -391,6 +393,8 @@ static struct redisCommand cmdTable[] = {
...
@@ -391,6 +393,8 @@ static struct redisCommand cmdTable[] = {
{
"sinterstore"
,
sinterstoreCommand
,
-
3
,
REDIS_CMD_INLINE
},
{
"sinterstore"
,
sinterstoreCommand
,
-
3
,
REDIS_CMD_INLINE
},
{
"sunion"
,
sunionCommand
,
-
2
,
REDIS_CMD_INLINE
},
{
"sunion"
,
sunionCommand
,
-
2
,
REDIS_CMD_INLINE
},
{
"sunionstore"
,
sunionstoreCommand
,
-
3
,
REDIS_CMD_INLINE
},
{
"sunionstore"
,
sunionstoreCommand
,
-
3
,
REDIS_CMD_INLINE
},
{
"sdiff"
,
sdiffCommand
,
-
2
,
REDIS_CMD_INLINE
},
{
"sdiffstore"
,
sdiffstoreCommand
,
-
3
,
REDIS_CMD_INLINE
},
{
"smembers"
,
sinterCommand
,
2
,
REDIS_CMD_INLINE
},
{
"smembers"
,
sinterCommand
,
2
,
REDIS_CMD_INLINE
},
{
"incrby"
,
incrbyCommand
,
3
,
REDIS_CMD_INLINE
},
{
"incrby"
,
incrbyCommand
,
3
,
REDIS_CMD_INLINE
},
{
"decrby"
,
decrbyCommand
,
3
,
REDIS_CMD_INLINE
},
{
"decrby"
,
decrbyCommand
,
3
,
REDIS_CMD_INLINE
},
...
@@ -3057,14 +3061,17 @@ static void sinterstoreCommand(redisClient *c) {
...
@@ -3057,14 +3061,17 @@ static void sinterstoreCommand(redisClient *c) {
sinterGenericCommand
(
c
,
c
->
argv
+
2
,
c
->
argc
-
2
,
c
->
argv
[
1
]);
sinterGenericCommand
(
c
,
c
->
argv
+
2
,
c
->
argc
-
2
,
c
->
argv
[
1
]);
}
}
static
void
sunionGenericCommand
(
redisClient
*
c
,
robj
**
setskeys
,
int
setsnum
,
robj
*
dstkey
)
{
#define REDIS_OP_UNION 0
#define REDIS_OP_DIFF 1
static
void
sunionDiffGenericCommand
(
redisClient
*
c
,
robj
**
setskeys
,
int
setsnum
,
robj
*
dstkey
,
int
op
)
{
dict
**
dv
=
zmalloc
(
sizeof
(
dict
*
)
*
setsnum
);
dict
**
dv
=
zmalloc
(
sizeof
(
dict
*
)
*
setsnum
);
dictIterator
*
di
;
dictIterator
*
di
;
dictEntry
*
de
;
dictEntry
*
de
;
robj
*
lenobj
=
NULL
,
*
dstset
=
NULL
;
robj
*
dstset
=
NULL
;
int
j
,
cardinality
=
0
;
int
j
,
cardinality
=
0
;
if
(
!
dv
)
oom
(
"sunionCommand"
);
if
(
!
dv
)
oom
(
"sunion
DiffGeneric
Command"
);
for
(
j
=
0
;
j
<
setsnum
;
j
++
)
{
for
(
j
=
0
;
j
<
setsnum
;
j
++
)
{
robj
*
setobj
;
robj
*
setobj
;
...
@@ -3093,11 +3100,7 @@ static void sunionGenericCommand(redisClient *c, robj **setskeys, int setsnum, r
...
@@ -3093,11 +3100,7 @@ static void sunionGenericCommand(redisClient *c, robj **setskeys, int setsnum, r
* the intersection set size, so we use a trick, append an empty object
* the intersection set size, so we use a trick, append an empty object
* to the output list and save the pointer to later modify it with the
* to the output list and save the pointer to later modify it with the
* right length */
* right length */
if
(
!
dstkey
)
{
if
(
dstkey
)
{
lenobj
=
createObject
(
REDIS_STRING
,
NULL
);
addReply
(
c
,
lenobj
);
decrRefCount
(
lenobj
);
}
else
{
/* If we have a target key where to store the resulting set
/* If we have a target key where to store the resulting set
* create this key with an empty set inside */
* create this key with an empty set inside */
deleteKey
(
c
->
db
,
dstkey
);
deleteKey
(
c
->
db
,
dstkey
);
...
@@ -3119,22 +3122,39 @@ static void sunionGenericCommand(redisClient *c, robj **setskeys, int setsnum, r
...
@@ -3119,22 +3122,39 @@ static void sunionGenericCommand(redisClient *c, robj **setskeys, int setsnum, r
/* dictAdd will not add the same element multiple times */
/* dictAdd will not add the same element multiple times */
ele
=
dictGetEntryKey
(
de
);
ele
=
dictGetEntryKey
(
de
);
if
(
dictAdd
(
dstset
->
ptr
,
ele
,
NULL
)
==
DICT_OK
)
{
if
(
op
==
REDIS_OP_UNION
||
j
==
0
)
{
incrRefCount
(
ele
);
if
(
dictAdd
(
dstset
->
ptr
,
ele
,
NULL
)
==
DICT_OK
)
{
if
(
!
dstkey
)
{
incrRefCount
(
ele
);
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
"$%d
\r\n
"
,
sdslen
(
ele
->
ptr
)));
addReply
(
c
,
ele
);
addReply
(
c
,
shared
.
crlf
);
cardinality
++
;
cardinality
++
;
}
}
}
else
if
(
op
==
REDIS_OP_DIFF
)
{
if
(
dictDelete
(
dstset
->
ptr
,
ele
)
==
DICT_OK
)
{
cardinality
--
;
}
}
}
}
}
dictReleaseIterator
(
di
);
dictReleaseIterator
(
di
);
}
}
/* Output the content of the resulting set, if not in STORE mode */
if
(
!
dstkey
)
{
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
"*%d
\r\n
"
,
cardinality
));
di
=
dictGetIterator
(
dstset
->
ptr
);
if
(
!
di
)
oom
(
"dictGetIterator"
);
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
robj
*
ele
;
ele
=
dictGetEntryKey
(
de
);
addReplySds
(
c
,
sdscatprintf
(
sdsempty
(),
"$%d
\r\n
"
,
sdslen
(
ele
->
ptr
)));
addReply
(
c
,
ele
);
addReply
(
c
,
shared
.
crlf
);
}
dictReleaseIterator
(
di
);
}
/* Cleanup */
if
(
!
dstkey
)
{
if
(
!
dstkey
)
{
lenobj
->
ptr
=
sdscatprintf
(
sdsempty
(),
"*%d
\r\n
"
,
cardinality
);
decrRefCount
(
dstset
);
decrRefCount
(
dstset
);
}
else
{
}
else
{
addReply
(
c
,
shared
.
ok
);
addReply
(
c
,
shared
.
ok
);
...
@@ -3144,11 +3164,19 @@ static void sunionGenericCommand(redisClient *c, robj **setskeys, int setsnum, r
...
@@ -3144,11 +3164,19 @@ static void sunionGenericCommand(redisClient *c, robj **setskeys, int setsnum, r
}
}
static
void
sunionCommand
(
redisClient
*
c
)
{
static
void
sunionCommand
(
redisClient
*
c
)
{
sunion
GenericCommand
(
c
,
c
->
argv
+
1
,
c
->
argc
-
1
,
NULL
);
sunion
DiffGenericCommand
(
c
,
c
->
argv
+
1
,
c
->
argc
-
1
,
NULL
,
REDIS_OP_UNION
);
}
}
static
void
sunionstoreCommand
(
redisClient
*
c
)
{
static
void
sunionstoreCommand
(
redisClient
*
c
)
{
sunionGenericCommand
(
c
,
c
->
argv
+
2
,
c
->
argc
-
2
,
c
->
argv
[
1
]);
sunionDiffGenericCommand
(
c
,
c
->
argv
+
2
,
c
->
argc
-
2
,
c
->
argv
[
1
],
REDIS_OP_UNION
);
}
static
void
sdiffCommand
(
redisClient
*
c
)
{
sunionDiffGenericCommand
(
c
,
c
->
argv
+
1
,
c
->
argc
-
1
,
NULL
,
REDIS_OP_DIFF
);
}
static
void
sdiffstoreCommand
(
redisClient
*
c
)
{
sunionDiffGenericCommand
(
c
,
c
->
argv
+
2
,
c
->
argc
-
2
,
c
->
argv
[
1
],
REDIS_OP_DIFF
);
}
}
static
void
flushdbCommand
(
redisClient
*
c
)
{
static
void
flushdbCommand
(
redisClient
*
c
)
{
...
...
test-redis.tcl
浏览文件 @
f4f56e1d
...
@@ -498,6 +498,23 @@ proc main {server port} {
...
@@ -498,6 +498,23 @@ proc main {server port} {
lsort
[
$r
sunion nokey1 set1 set2 nokey2
]
lsort
[
$r
sunion nokey1 set1 set2 nokey2
]
}
[
lsort -uniq
"
[
$r
smembers set1
]
[
$r
smembers set2
]
"
]
}
[
lsort -uniq
"
[
$r
smembers set1
]
[
$r
smembers set2
]
"
]
test
{
SDIFF with two sets
}
{
for
{
set i 5
}
{
$i
< 1000
}
{
incr i
}
{
$r sadd set4 $i
}
lsort
[
$r
sdiff set1 set4
]
}
{
0 1 2 3 4
}
test
{
SDIFF with three sets
}
{
$r sadd set5 0
lsort
[
$r
sdiff set1 set4 set5
]
}
{
1 2 3 4
}
test
{
SDIFFSTORE with three sets
}
{
$r sdiffstore sres set1 set4 set5
lsort
[
$r
smembers sres
]
}
{
1 2 3 4
}
test
{
SAVE - make sure there are all the types as values
}
{
test
{
SAVE - make sure there are all the types as values
}
{
$r lpush mysavelist hello
$r lpush mysavelist hello
$r lpush mysavelist world
$r lpush mysavelist world
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录