Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
OpenAtomFoundation
pika
提交
3d889e0f
pika
项目概览
镜像
/
OpenAtomFoundation
/
pika
11 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
pika
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3d889e0f
编写于
8月 19, 2015
作者:
S
songzhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add hincrbyfloat
上级
200e5606
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
56 addition
and
2 deletion
+56
-2
include/pika_command.h
include/pika_command.h
+6
-0
include/util.h
include/util.h
+1
-0
src/pika.cc
src/pika.cc
+2
-0
src/pika_hash.cc
src/pika_hash.cc
+37
-2
src/util.cc
src/util.cc
+10
-0
未找到文件。
include/pika_command.h
浏览文件 @
3d889e0f
...
...
@@ -72,6 +72,12 @@ public:
virtual
void
Do
(
std
::
list
<
std
::
string
>
&
argvs
,
std
::
string
&
ret
);
};
class
HIncrbyfloatCmd
:
public
Cmd
{
public:
HIncrbyfloatCmd
(
int
a
)
:
Cmd
(
a
)
{};
virtual
void
Do
(
std
::
list
<
std
::
string
>
&
argvs
,
std
::
string
&
ret
);
};
class
HKeysCmd
:
public
Cmd
{
public:
HKeysCmd
(
int
a
)
:
Cmd
(
a
)
{};
...
...
include/util.h
浏览文件 @
3d889e0f
...
...
@@ -39,6 +39,7 @@ int ll2string(char *s, size_t len, long long value);
int
string2ll
(
const
char
*
s
,
size_t
slen
,
long
long
*
value
);
int
string2l
(
const
char
*
s
,
size_t
slen
,
long
*
value
);
int
d2string
(
char
*
buf
,
size_t
len
,
double
value
);
int
string2d
(
const
char
*
buf
,
size_t
len
,
double
*
value
);
sds
getAbsolutePath
(
char
*
filename
);
int
pathIsBaseName
(
char
*
path
);
...
...
src/pika.cc
浏览文件 @
3d889e0f
...
...
@@ -141,6 +141,8 @@ int main(int argc, char **argv)
g_pikaCmd
.
insert
(
std
::
pair
<
std
::
string
,
Cmd
*>
(
"hgetall"
,
hgetallptr
));
HIncrbyCmd
*
hincrbyptr
=
new
HIncrbyCmd
(
4
);
g_pikaCmd
.
insert
(
std
::
pair
<
std
::
string
,
Cmd
*>
(
"hincrby"
,
hincrbyptr
));
HIncrbyfloatCmd
*
hincrbyfloatptr
=
new
HIncrbyfloatCmd
(
4
);
g_pikaCmd
.
insert
(
std
::
pair
<
std
::
string
,
Cmd
*>
(
"hincrbyfloat"
,
hincrbyfloatptr
));
HKeysCmd
*
hkeysptr
=
new
HKeysCmd
(
2
);
g_pikaCmd
.
insert
(
std
::
pair
<
std
::
string
,
Cmd
*>
(
"hkeys"
,
hkeysptr
));
HLenCmd
*
hlenptr
=
new
HLenCmd
(
2
);
...
...
src/pika_hash.cc
浏览文件 @
3d889e0f
...
...
@@ -136,9 +136,8 @@ void HIncrbyCmd::Do(std::list<std::string> &argv, std::string &ret) {
}
nemo
::
Status
s
=
g_pikaServer
->
GetHandle
()
->
HIncrby
(
key
,
field
,
by
,
new_val
);
if
(
s
.
ok
()
||
s
.
IsNotFound
())
{
char
buf
[
32
];
ret
=
":"
;
ret
.
append
(
new_val
);
ret
.
append
(
new_val
.
data
(),
new_val
.
size
()
);
ret
.
append
(
"
\r\n
"
);
}
else
if
(
s
.
IsCorruption
()
&&
s
.
ToString
()
==
"Corruption: value is not integer"
){
ret
=
"-ERR hash value is not an integer
\r\n
"
;
...
...
@@ -149,6 +148,42 @@ void HIncrbyCmd::Do(std::list<std::string> &argv, std::string &ret) {
}
}
void
HIncrbyfloatCmd
::
Do
(
std
::
list
<
std
::
string
>
&
argv
,
std
::
string
&
ret
)
{
if
((
arity
>
0
&&
(
int
)
argv
.
size
()
!=
arity
)
||
(
arity
<
0
&&
(
int
)
argv
.
size
()
<
-
arity
))
{
ret
=
"-ERR wrong number of arguments for "
;
ret
.
append
(
argv
.
front
());
ret
.
append
(
" command
\r\n
"
);
return
;
}
argv
.
pop_front
();
std
::
string
key
=
argv
.
front
();
argv
.
pop_front
();
std
::
string
field
=
argv
.
front
();
argv
.
pop_front
();
std
::
string
str_by
=
argv
.
front
();
argv
.
pop_front
();
double
by
;
std
::
string
new_val
;
if
(
!
string2d
(
str_by
.
data
(),
str_by
.
size
(),
&
by
))
{
ret
=
"-ERR value is not an float
\r\n
"
;
return
;
}
nemo
::
Status
s
=
g_pikaServer
->
GetHandle
()
->
HIncrbyfloat
(
key
,
field
,
by
,
new_val
);
if
(
s
.
ok
()
||
s
.
IsNotFound
())
{
char
buf
[
32
];
snprintf
(
buf
,
sizeof
(
buf
),
"$%lu
\r\n
"
,
new_val
.
size
());
ret
.
append
(
buf
);
ret
.
append
(
new_val
.
data
(),
new_val
.
size
());
ret
.
append
(
"
\r\n
"
);
}
else
if
(
s
.
IsCorruption
()
&&
s
.
ToString
()
==
"Corruption: value is not float"
){
ret
=
"-ERR hash value is not an float
\r\n
"
;
}
else
{
ret
.
append
(
"-ERR "
);
ret
.
append
(
s
.
ToString
().
c_str
());
ret
.
append
(
"
\r\n
"
);
}
}
void
HKeysCmd
::
Do
(
std
::
list
<
std
::
string
>
&
argv
,
std
::
string
&
ret
)
{
if
((
arity
>
0
&&
(
int
)
argv
.
size
()
!=
arity
)
||
(
arity
<
0
&&
(
int
)
argv
.
size
()
<
-
arity
))
{
ret
=
"-ERR wrong number of arguments for "
;
...
...
src/util.cc
浏览文件 @
3d889e0f
...
...
@@ -424,6 +424,16 @@ int d2string(char *buf, size_t len, double value) {
return
len
;
}
int
string2d
(
const
char
*
s
,
size_t
slen
,
double
*
dval
)
{
char
*
pEnd
;
double
d
=
strtod
(
s
,
&
pEnd
);
if
(
pEnd
!=
s
+
slen
)
return
0
;
if
(
dval
!=
NULL
)
*
dval
=
d
;
return
1
;
}
/* Generate the Redis "Run ID", a SHA1-sized random number that identifies a
* given execution of Redis, so that if you are talking with an instance
* having run_id == A, and you reconnect and it has run_id == B, you can be
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录