Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hanoi2005
redis
提交
724a51b1
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,发现更多精彩内容 >>
提交
724a51b1
编写于
9月 18, 2009
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
LREM fixed, used to crash since the new object integer encoding is on the stage
上级
d4465900
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
11 deletion
+54
-11
redis.c
redis.c
+46
-11
test-redis.tcl
test-redis.tcl
+8
-0
未找到文件。
redis.c
浏览文件 @
724a51b1
...
...
@@ -1836,10 +1836,31 @@ static robj *tryObjectSharing(robj *o) {
}
}
/* Check if the nul-terminated string 's' can be represented by a long
* (that is, is a number that fits into long without any other space or
* character before or after the digits).
*
* If so, the function returns REDIS_OK and *longval is set to the value
* of the number. Otherwise REDIS_ERR is returned */
static
int
isStringRepresentableAsLong
(
char
*
s
,
long
*
longval
)
{
char
buf
[
32
],
*
endptr
;
long
value
;
int
slen
;
value
=
strtol
(
s
,
&
endptr
,
10
);
if
(
endptr
[
0
]
!=
'\0'
)
return
REDIS_ERR
;
slen
=
snprintf
(
buf
,
32
,
"%ld"
,
value
);
/* If the number converted back into a string is not identical
* then it's not possible to encode the string as integer */
if
(
strlen
(
buf
)
!=
(
unsigned
)
slen
||
memcmp
(
buf
,
s
,
slen
))
return
REDIS_ERR
;
if
(
longval
)
*
longval
=
value
;
return
REDIS_OK
;
}
/* Try to encode a string object in order to save space */
static
int
tryObjectEncoding
(
robj
*
o
)
{
long
value
;
char
*
endptr
,
buf
[
32
];
sds
s
=
o
->
ptr
;
if
(
o
->
encoding
!=
REDIS_ENCODING_RAW
)
...
...
@@ -1853,15 +1874,8 @@ static int tryObjectEncoding(robj *o) {
/* Currently we try to encode only strings */
assert
(
o
->
type
==
REDIS_STRING
);
/* Check if it's possible to encode this value as a long. We are assuming
* that sizeof(long) = sizeof(void) in all the supported archs. */
value
=
strtol
(
s
,
&
endptr
,
10
);
if
(
endptr
[
0
]
!=
'\0'
)
return
REDIS_ERR
;
snprintf
(
buf
,
32
,
"%ld"
,
value
);
/* If the number converted back into a string is not identical
* then it's not possible to encode the string as integer */
if
(
strlen
(
buf
)
!=
sdslen
(
s
)
||
memcmp
(
buf
,
s
,
sdslen
(
s
)))
return
REDIS_ERR
;
/* Check if we can represent this string as a long integer */
if
(
isStringRepresentableAsLong
(
s
,
&
value
)
==
REDIS_ERR
)
return
REDIS_ERR
;
/* Ok, this object can be encoded */
o
->
encoding
=
REDIS_ENCODING_INT
;
...
...
@@ -1886,6 +1900,25 @@ static robj *getDecodedObject(const robj *o) {
}
}
static
int
compareStringObjects
(
robj
*
a
,
robj
*
b
)
{
assert
(
a
->
type
==
REDIS_STRING
&&
b
->
type
==
REDIS_STRING
);
if
(
a
->
encoding
==
REDIS_ENCODING_INT
&&
b
->
encoding
==
REDIS_ENCODING_INT
){
return
(
long
)
a
->
ptr
-
(
long
)
b
->
ptr
;
}
else
{
int
retval
;
incrRefCount
(
a
);
incrRefCount
(
b
);
if
(
a
->
encoding
!=
REDIS_ENCODING_RAW
)
a
=
getDecodedObject
(
a
);
if
(
b
->
encoding
!=
REDIS_ENCODING_RAW
)
b
=
getDecodedObject
(
a
);
retval
=
sdscmp
(
a
->
ptr
,
b
->
ptr
);
decrRefCount
(
a
);
decrRefCount
(
b
);
return
retval
;
}
}
/*============================ DB saving/loading ============================ */
static
int
rdbSaveType
(
FILE
*
fp
,
unsigned
char
type
)
{
...
...
@@ -3090,7 +3123,7 @@ static void lremCommand(redisClient *c) {
robj
*
ele
=
listNodeValue
(
ln
);
next
=
fromtail
?
ln
->
prev
:
ln
->
next
;
if
(
sdscmp
(
ele
->
ptr
,
c
->
argv
[
3
]
->
ptr
)
==
0
)
{
if
(
compareStringObjects
(
ele
,
c
->
argv
[
3
]
)
==
0
)
{
listDelNode
(
list
,
ln
);
server
.
dirty
++
;
removed
++
;
...
...
@@ -4375,6 +4408,8 @@ static void debugCommand(redisClient *c) {
#ifdef HAVE_BACKTRACE
static
struct
redisFunctionSym
symsTable
[]
=
{
{
"compareStringObjects"
,
(
unsigned
long
)
compareStringObjects
},
{
"isStringRepresentableAsLong"
,
(
unsigned
long
)
isStringRepresentableAsLong
},
{
"dictEncObjKeyCompare"
,
(
unsigned
long
)
dictEncObjKeyCompare
},
{
"dictEncObjHash"
,
(
unsigned
long
)
dictEncObjHash
},
{
"incrDecrCommand"
,
(
unsigned
long
)
incrDecrCommand
},
...
...
test-redis.tcl
浏览文件 @
724a51b1
...
...
@@ -651,6 +651,14 @@ proc main {server port} {
list
[
$r
lrange mylist 0 -1
]
$res
}
{{
foo bar foobar foobared zap test
}
2
}
test
{
LREM, deleting objects that may be encoded as integers
}
{
$r lpush myotherlist 1
$r lpush myotherlist 2
$r lpush myotherlist 3
$r lrem myotherlist 1 2
$r llen myotherlist
}
{
2
}
test
{
MGET
}
{
$r flushall
$r set foo BAR
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录