Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
24aa6178
R
redis
项目概览
hanoi2005
/
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,发现更多精彩内容 >>
提交
24aa6178
编写于
3月 28, 2013
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extended SET command implemented (issue #931).
上级
e6e07042
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
59 addition
and
9 deletion
+59
-9
src/redis.c
src/redis.c
+1
-1
src/t_string.c
src/t_string.c
+58
-8
未找到文件。
src/redis.c
浏览文件 @
24aa6178
...
...
@@ -114,7 +114,7 @@ struct redisCommand *commandTable;
*/
struct
redisCommand
redisCommandTable
[]
=
{
{
"get"
,
getCommand
,
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"set"
,
setCommand
,
3
,
"wm"
,
0
,
noPreloadGetKeys
,
1
,
1
,
1
,
0
,
0
},
{
"set"
,
setCommand
,
-
3
,
"wm"
,
0
,
noPreloadGetKeys
,
1
,
1
,
1
,
0
,
0
},
{
"setnx"
,
setnxCommand
,
3
,
"wm"
,
0
,
noPreloadGetKeys
,
1
,
1
,
1
,
0
,
0
},
{
"setex"
,
setexCommand
,
4
,
"wm"
,
0
,
noPreloadGetKeys
,
1
,
1
,
1
,
0
,
0
},
{
"psetex"
,
psetexCommand
,
4
,
"wm"
,
0
,
noPreloadGetKeys
,
1
,
1
,
1
,
0
,
0
},
...
...
src/t_string.c
浏览文件 @
24aa6178
...
...
@@ -42,7 +42,27 @@ static int checkStringLength(redisClient *c, long long size) {
return
REDIS_OK
;
}
void
setGenericCommand
(
redisClient
*
c
,
int
nx
,
robj
*
key
,
robj
*
val
,
robj
*
expire
,
int
unit
)
{
/* The setGenericCommand() function implements the SET operation with different
* options and variants. This function is called in order to implement the
* following commands: SET, SETEX, PSETEX, SETNX.
*
* 'flags' changes the behavior of the command (NX or XX, see belove).
*
* 'expire' represents an expire to set in form of a Redis object as passed
* by the user. It is interpreted according to the specified 'unit'.
*
* 'ok_reply' and 'abort_reply' is what the function will reply to the client
* if the operation is performed, or when it is not because of NX or
* XX flags.
*
* If ok_reply is NULL "+OK" is used.
* If abort_reply is NULL, "$-1" is used. */
#define REDIS_SET_NO_FLAGS 0
#define REDIS_SET_NX (1<<0)
/* Set if key not exists. */
#define REDIS_SET_XX (1<<1)
/* Set if key exists. */
void
setGenericCommand
(
redisClient
*
c
,
int
flags
,
robj
*
key
,
robj
*
val
,
robj
*
expire
,
int
unit
,
robj
*
ok_reply
,
robj
*
abort_reply
)
{
long
long
milliseconds
=
0
;
/* initialized to avoid any harmness warning */
if
(
expire
)
{
...
...
@@ -55,8 +75,10 @@ void setGenericCommand(redisClient *c, int nx, robj *key, robj *val, robj *expir
if
(
unit
==
UNIT_SECONDS
)
milliseconds
*=
1000
;
}
if
(
nx
&&
lookupKeyWrite
(
c
->
db
,
key
)
!=
NULL
)
{
addReply
(
c
,
shared
.
czero
);
if
((
flags
&
REDIS_SET_NX
&&
lookupKeyWrite
(
c
->
db
,
key
)
!=
NULL
)
||
(
flags
&
REDIS_SET_XX
&&
lookupKeyWrite
(
c
->
db
,
key
)
==
NULL
))
{
addReply
(
c
,
abort_reply
?
abort_reply
:
shared
.
nullbulk
);
return
;
}
setKey
(
c
->
db
,
key
,
val
);
...
...
@@ -65,27 +87,55 @@ void setGenericCommand(redisClient *c, int nx, robj *key, robj *val, robj *expir
notifyKeyspaceEvent
(
REDIS_NOTIFY_STRING
,
"set"
,
key
,
c
->
db
->
id
);
if
(
expire
)
notifyKeyspaceEvent
(
REDIS_NOTIFY_GENERIC
,
"expire"
,
key
,
c
->
db
->
id
);
addReply
(
c
,
nx
?
shared
.
cone
:
shared
.
ok
);
addReply
(
c
,
ok_reply
?
ok_reply
:
shared
.
ok
);
}
/* SET key value [NX] [XX] [EX <seconds>] [PX <milliseconds>] */
void
setCommand
(
redisClient
*
c
)
{
int
j
;
robj
*
expire
=
NULL
;
int
unit
=
UNIT_SECONDS
;
int
flags
=
REDIS_SET_NO_FLAGS
;
for
(
j
=
3
;
j
<
c
->
argc
;
j
++
)
{
char
*
a
=
c
->
argv
[
j
]
->
ptr
;
robj
*
next
=
(
j
==
c
->
argc
-
1
)
?
NULL
:
c
->
argv
[
j
+
1
];
if
(
a
[
0
]
==
'n'
&&
a
[
1
]
==
'x'
&&
a
[
2
]
==
'\0'
)
{
flags
|=
REDIS_SET_NX
;
}
else
if
(
a
[
0
]
==
'x'
&&
a
[
1
]
==
'x'
&&
a
[
2
]
==
'\0'
)
{
flags
|=
REDIS_SET_XX
;
}
else
if
(
a
[
0
]
==
'e'
&&
a
[
1
]
==
'x'
&&
a
[
2
]
==
'\0'
&&
next
)
{
unit
=
UNIT_SECONDS
;
expire
=
next
;
j
++
;
}
else
if
(
a
[
0
]
==
'p'
&&
a
[
1
]
==
'x'
&&
a
[
2
]
==
'\0'
&&
next
)
{
unit
=
UNIT_MILLISECONDS
;
expire
=
next
;
j
++
;
}
else
{
addReply
(
c
,
shared
.
syntaxerr
);
return
;
}
}
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
setGenericCommand
(
c
,
0
,
c
->
argv
[
1
],
c
->
argv
[
2
],
NULL
,
0
);
setGenericCommand
(
c
,
flags
,
c
->
argv
[
1
],
c
->
argv
[
2
],
expire
,
unit
,
NULL
,
NULL
);
}
void
setnxCommand
(
redisClient
*
c
)
{
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
setGenericCommand
(
c
,
1
,
c
->
argv
[
1
],
c
->
argv
[
2
],
NULL
,
0
);
setGenericCommand
(
c
,
REDIS_SET_NX
,
c
->
argv
[
1
],
c
->
argv
[
2
],
NULL
,
0
,
shared
.
cone
,
shared
.
czero
);
}
void
setexCommand
(
redisClient
*
c
)
{
c
->
argv
[
3
]
=
tryObjectEncoding
(
c
->
argv
[
3
]);
setGenericCommand
(
c
,
0
,
c
->
argv
[
1
],
c
->
argv
[
3
],
c
->
argv
[
2
],
UNIT_SECONDS
);
setGenericCommand
(
c
,
REDIS_SET_NO_FLAGS
,
c
->
argv
[
1
],
c
->
argv
[
3
],
c
->
argv
[
2
],
UNIT_SECONDS
,
NULL
,
NULL
);
}
void
psetexCommand
(
redisClient
*
c
)
{
c
->
argv
[
3
]
=
tryObjectEncoding
(
c
->
argv
[
3
]);
setGenericCommand
(
c
,
0
,
c
->
argv
[
1
],
c
->
argv
[
3
],
c
->
argv
[
2
],
UNIT_MILLISECONDS
);
setGenericCommand
(
c
,
REDIS_SET_NO_FLAGS
,
c
->
argv
[
1
],
c
->
argv
[
3
],
c
->
argv
[
2
],
UNIT_MILLISECONDS
,
NULL
,
NULL
);
}
int
getGenericCommand
(
redisClient
*
c
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录