Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
1f1c7695
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,发现更多精彩内容 >>
提交
1f1c7695
编写于
4月 15, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added HSETNX
上级
7fb16bac
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
41 addition
and
1 deletion
+41
-1
redis.c
redis.c
+16
-0
redis.tcl
redis.tcl
+1
-1
test-redis.tcl
test-redis.tcl
+24
-0
未找到文件。
redis.c
浏览文件 @
1f1c7695
...
...
@@ -705,6 +705,7 @@ static void substrCommand(redisClient *c);
static
void
zrankCommand
(
redisClient
*
c
);
static
void
zrevrankCommand
(
redisClient
*
c
);
static
void
hsetCommand
(
redisClient
*
c
);
static
void
hsetnxCommand
(
redisClient
*
c
);
static
void
hgetCommand
(
redisClient
*
c
);
static
void
hmsetCommand
(
redisClient
*
c
);
static
void
hmgetCommand
(
redisClient
*
c
);
...
...
@@ -783,6 +784,7 @@ static struct redisCommand cmdTable[] = {
{
"zrank"
,
zrankCommand
,
3
,
REDIS_CMD_BULK
,
NULL
,
1
,
1
,
1
},
{
"zrevrank"
,
zrevrankCommand
,
3
,
REDIS_CMD_BULK
,
NULL
,
1
,
1
,
1
},
{
"hset"
,
hsetCommand
,
4
,
REDIS_CMD_BULK
|
REDIS_CMD_DENYOOM
,
NULL
,
1
,
1
,
1
},
{
"hsetnx"
,
hsetnxCommand
,
4
,
REDIS_CMD_BULK
|
REDIS_CMD_DENYOOM
,
NULL
,
1
,
1
,
1
},
{
"hget"
,
hgetCommand
,
3
,
REDIS_CMD_BULK
,
NULL
,
1
,
1
,
1
},
{
"hmset"
,
hmsetCommand
,
-
4
,
REDIS_CMD_BULK
|
REDIS_CMD_DENYOOM
,
NULL
,
1
,
1
,
1
},
{
"hmget"
,
hmgetCommand
,
-
3
,
REDIS_CMD_BULK
,
NULL
,
1
,
1
,
1
},
...
...
@@ -6247,6 +6249,20 @@ static void hsetCommand(redisClient *c) {
server
.
dirty
++
;
}
static
void
hsetnxCommand
(
redisClient
*
c
)
{
robj
*
o
;
if
((
o
=
hashLookupWriteOrCreate
(
c
,
c
->
argv
[
1
]))
==
NULL
)
return
;
hashTryConversion
(
o
,
c
->
argv
,
2
,
3
);
if
(
hashExists
(
o
,
c
->
argv
[
2
]))
{
addReply
(
c
,
shared
.
czero
);
}
else
{
hashReplace
(
o
,
c
->
argv
[
2
],
c
->
argv
[
3
]);
addReply
(
c
,
shared
.
cone
);
server
.
dirty
++
;
}
}
static
void
hmsetCommand
(
redisClient
*
c
)
{
int
i
;
robj
*
o
;
...
...
redis.tcl
浏览文件 @
1f1c7695
...
...
@@ -46,7 +46,7 @@ foreach redis_bulk_cmd {
# Flag commands requiring last argument as a bulk write operation
foreach redis_multibulk_cmd
{
mset msetnx hset hmset hmget
mset msetnx hset h
setnx h
mset hmget
}
{
set ::redis::multibulkarg
(
$redis
_multibulk_cmd
)
{}
}
...
...
test-redis.tcl
浏览文件 @
1f1c7695
...
...
@@ -1652,6 +1652,30 @@ proc main {} {
set _ $rv
}
{
0 newval1 1 0 newval2 1 1 1
}
test
{
HSETNX target key missing - small hash
}
{
$r hsetnx smallhash __123123123__ foo
$r hget smallhash __123123123__
}
{
foo
}
test
{
HSETNX target key exists - small hash
}
{
$r hsetnx smallhash __123123123__ bar
set result
[
$r
hget smallhash __123123123__
]
$r hdel smallhash __123123123__
set _ $result
}
{
foo
}
test
{
HSETNX target key missing - big hash
}
{
$r hsetnx bighash __123123123__ foo
$r hget bighash __123123123__
}
{
foo
}
test
{
HSETNX target key exists - big hash
}
{
$r hsetnx bighash __123123123__ bar
set result
[
$r
hget bighash __123123123__
]
$r hdel bighash __123123123__
set _ $result
}
{
foo
}
test
{
HMSET wrong number of args
}
{
catch
{
$r
hmset smallhash key1 val1 key2
}
err
format $err
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录