Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
33b5f22e
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,体验更适合开发者的 AI 搜索 >>
提交
33b5f22e
编写于
4月 04, 2014
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Non-LZF aware object.c APIs fixed.
上级
61671a0d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
9 deletion
+49
-9
src/object.c
src/object.c
+49
-9
未找到文件。
src/object.c
浏览文件 @
33b5f22e
...
...
@@ -150,6 +150,10 @@ robj *dupStringObject(robj *o) {
d
->
encoding
=
REDIS_ENCODING_INT
;
d
->
ptr
=
o
->
ptr
;
return
d
;
case
REDIS_ENCODING_LZF
:
d
=
createObject
(
REDIS_STRING
,
sdsdup
(
o
->
ptr
));
d
->
encoding
=
REDIS_ENCODING_LZF
;
return
d
;
default:
redisPanic
(
"Wrong encoding."
);
break
;
...
...
@@ -329,11 +333,19 @@ int checkType(redisClient *c, robj *o, int type) {
int
isObjectRepresentableAsLongLong
(
robj
*
o
,
long
long
*
llval
)
{
redisAssertWithInfo
(
NULL
,
o
,
o
->
type
==
REDIS_STRING
);
if
(
o
->
encoding
==
REDIS_ENCODING_INT
)
{
if
(
intEncodedObject
(
o
)
)
{
if
(
llval
)
*
llval
=
(
long
)
o
->
ptr
;
return
REDIS_OK
;
}
else
{
}
else
if
(
sdsEncodedObject
(
o
))
{
return
string2ll
(
o
->
ptr
,
sdslen
(
o
->
ptr
),
llval
)
?
REDIS_OK
:
REDIS_ERR
;
}
else
if
(
lzfEncodedObject
(
o
))
{
int
retval
;
robj
*
decoded
=
getDecodedObject
(
o
);
retval
=
string2ll
(
o
->
ptr
,
sdslen
(
o
->
ptr
),
llval
)
?
REDIS_OK
:
REDIS_ERR
;
decrRefCount
(
decoded
);
return
retval
;
}
else
{
redisPanic
(
"Unknown encoding."
);
}
}
...
...
@@ -464,13 +476,13 @@ robj *getDecodedObject(robj *o) {
incrRefCount
(
o
);
return
o
;
}
if
(
o
->
type
==
REDIS_STRING
&&
o
->
encoding
==
REDIS_ENCODING_INT
)
{
if
(
o
->
type
==
REDIS_STRING
&&
intEncodedObject
(
o
)
)
{
char
buf
[
32
];
ll2string
(
buf
,
32
,(
long
)
o
->
ptr
);
dec
=
createStringObject
(
buf
,
strlen
(
buf
));
return
dec
;
}
else
if
(
o
->
type
==
REDIS_STRING
&&
o
->
encoding
==
REDIS_ENCODING_LZF
)
{
}
else
if
(
o
->
type
==
REDIS_STRING
&&
lzfEncodedObject
(
o
)
)
{
int
origlen
=
stringObjectLen
(
o
);
sds
orig
=
sdsnewlen
(
NULL
,
origlen
);
unsigned
char
*
p
=
o
->
ptr
;
...
...
@@ -498,8 +510,15 @@ int compareStringObjectsWithFlags(robj *a, robj *b, int flags) {
redisAssertWithInfo
(
NULL
,
a
,
a
->
type
==
REDIS_STRING
&&
b
->
type
==
REDIS_STRING
);
char
bufa
[
128
],
bufb
[
128
],
*
astr
,
*
bstr
;
size_t
alen
,
blen
,
minlen
;
int
decr
=
0
;
if
(
a
==
b
)
return
0
;
if
(
lzfEncodedObject
(
a
)
||
lzfEncodedObject
(
b
))
{
a
=
getDecodedObject
(
a
);
b
=
getDecodedObject
(
b
);
decr
=
1
;
}
if
(
sdsEncodedObject
(
a
))
{
astr
=
a
->
ptr
;
alen
=
sdslen
(
astr
);
...
...
@@ -524,6 +543,10 @@ int compareStringObjectsWithFlags(robj *a, robj *b, int flags) {
if
(
cmp
==
0
)
return
alen
-
blen
;
return
cmp
;
}
if
(
decr
)
{
decrRefCount
(
a
);
decrRefCount
(
b
);
}
}
/* Wrapper for compareStringObjectsWithFlags() using binary comparison. */
...
...
@@ -541,8 +564,7 @@ int collateStringObjects(robj *a, robj *b) {
* this function is faster then checking for (compareStringObject(a,b) == 0)
* because it can perform some more optimization. */
int
equalStringObjects
(
robj
*
a
,
robj
*
b
)
{
if
(
a
->
encoding
==
REDIS_ENCODING_INT
&&
b
->
encoding
==
REDIS_ENCODING_INT
){
if
(
intEncodedObject
(
a
)
&&
intEncodedObject
(
b
))
{
/* If both strings are integer encoded just check if the stored
* long is the same. */
return
a
->
ptr
==
b
->
ptr
;
...
...
@@ -588,8 +610,14 @@ int getDoubleFromObject(robj *o, double *target) {
errno
==
EINVAL
||
isnan
(
value
))
return
REDIS_ERR
;
}
else
if
(
o
->
encoding
==
REDIS_ENCODING_INT
)
{
}
else
if
(
intEncodedObject
(
o
)
)
{
value
=
(
long
)
o
->
ptr
;
}
else
if
(
lzfEncodedObject
(
o
))
{
int
retval
;
o
=
getDecodedObject
(
o
);
retval
=
getDoubleFromObject
(
o
,
target
);
decrRefCount
(
o
);
return
retval
;
}
else
{
redisPanic
(
"Unknown string encoding"
);
}
...
...
@@ -626,8 +654,14 @@ int getLongDoubleFromObject(robj *o, long double *target) {
if
(
isspace
(((
char
*
)
o
->
ptr
)[
0
])
||
eptr
[
0
]
!=
'\0'
||
errno
==
ERANGE
||
isnan
(
value
))
return
REDIS_ERR
;
}
else
if
(
o
->
encoding
==
REDIS_ENCODING_INT
)
{
}
else
if
(
intEncodedObject
(
o
)
)
{
value
=
(
long
)
o
->
ptr
;
}
else
if
(
lzfEncodedObject
(
o
))
{
int
retval
;
o
=
getDecodedObject
(
o
);
retval
=
getLongDoubleFromObject
(
o
,
target
);
decrRefCount
(
o
);
return
retval
;
}
else
{
redisPanic
(
"Unknown string encoding"
);
}
...
...
@@ -664,8 +698,14 @@ int getLongLongFromObject(robj *o, long long *target) {
if
(
isspace
(((
char
*
)
o
->
ptr
)[
0
])
||
eptr
[
0
]
!=
'\0'
||
errno
==
ERANGE
)
return
REDIS_ERR
;
}
else
if
(
o
->
encoding
==
REDIS_ENCODING_INT
)
{
}
else
if
(
intEncodedObject
(
o
)
)
{
value
=
(
long
)
o
->
ptr
;
}
else
if
(
lzfEncodedObject
(
o
))
{
int
retval
;
o
=
getDecodedObject
(
o
);
retval
=
getLongLongFromObject
(
o
,
target
);
decrRefCount
(
o
);
return
retval
;
}
else
{
redisPanic
(
"Unknown string encoding"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录