Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
70b4b320
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,发现更多精彩内容 >>
提交
70b4b320
编写于
6月 11, 2010
作者:
P
Pieter Noordhuis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
check if the list encoding needs to be changed on LPUSHX, RPUSHX, LINSERT
上级
244b873b
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
102 addition
and
54 deletion
+102
-54
redis.c
redis.c
+19
-2
tests/unit/type/list.tcl
tests/unit/type/list.tcl
+83
-52
未找到文件。
redis.c
浏览文件 @
70b4b320
...
...
@@ -4926,7 +4926,7 @@ static void listTypePush(robj *subject, robj *value, int where) {
/* Check if we need to convert the ziplist */
listTypeTryConversion
(
subject
,
value
);
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
&&
ziplistLen
(
subject
->
ptr
)
>
server
.
list_max_ziplist_entries
)
ziplistLen
(
subject
->
ptr
)
>
=
server
.
list_max_ziplist_entries
)
listTypeConvert
(
subject
,
REDIS_ENCODING_LIST
);
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
...
...
@@ -5214,6 +5214,7 @@ static void pushxGenericCommand(redisClient *c, robj *refval, robj *val, int whe
robj
*
subject
;
listTypeIterator
*
iter
;
listTypeEntry
entry
;
int
inserted
=
0
;
if
((
subject
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
checkType
(
c
,
subject
,
REDIS_LIST
))
return
;
...
...
@@ -5227,20 +5228,36 @@ static void pushxGenericCommand(redisClient *c, robj *refval, robj *val, int whe
* last argument of the multi-bulk LINSERT. */
redisAssert
(
refval
->
encoding
==
REDIS_ENCODING_RAW
);
/* We're not sure if this value can be inserted yet, but we cannot
* convert the list inside the iterator. We don't want to loop over
* the list twice (once to see if the value can be inserted and once
* to do the actual insert), so we assume this value can be inserted
* and convert the ziplist to a regular list if necessary. */
listTypeTryConversion
(
subject
,
val
);
/* Seek refval from head to tail */
iter
=
listTypeInitIterator
(
subject
,
0
,
REDIS_TAIL
);
while
(
listTypeNext
(
iter
,
&
entry
))
{
if
(
listTypeEqual
(
&
entry
,
refval
))
{
listTypeInsert
(
&
entry
,
val
,
where
);
inserted
=
1
;
break
;
}
}
listTypeReleaseIterator
(
iter
);
if
(
inserted
)
{
/* Check if the length exceeds the ziplist length threshold. */
if
(
subject
->
encoding
==
REDIS_ENCODING_ZIPLIST
&&
ziplistLen
(
subject
->
ptr
)
>
server
.
list_max_ziplist_entries
)
listTypeConvert
(
subject
,
REDIS_ENCODING_LIST
);
server
.
dirty
++
;
}
}
else
{
listTypePush
(
subject
,
val
,
where
);
server
.
dirty
++
;
}
server
.
dirty
++
;
addReplyUlong
(
c
,
listTypeLength
(
subject
));
}
...
...
tests/unit/type/list.tcl
浏览文件 @
70b4b320
...
...
@@ -52,17 +52,50 @@ start_server {
assert_equal $large_value
[
r lindex mylist2 2
]
}
test
{
LPUSHX, RPUSHX, LPUSHXAFTER, RPUSHXAFTER - ziplist
}
{
test
{
DEL a list - ziplist
}
{
assert_equal 1
[
r del myziplist2
]
assert_equal 0
[
r exists myziplist2
]
assert_equal 0
[
r llen myziplist2
]
}
test
{
DEL a list - regular list
}
{
assert_equal 1
[
r del mylist2
]
assert_equal 0
[
r exists mylist2
]
assert_equal 0
[
r llen mylist2
]
}
proc create_ziplist
{
key entries
}
{
r del $key
foreach entry $entries
{
r rpush $key $entry
}
assert_encoding ziplist $key
}
proc create_list
{
key entries
}
{
r del $key
r rpush $key
"aaaaaaaaaaaaaaaaa"
foreach entry $entries
{
r rpush $key $entry
}
assert_equal
"aaaaaaaaaaaaaaaaa"
[
r lpop $key
]
assert_encoding list $key
}
test
{
LPUSHX, RPUSHX - generic
}
{
r del xlist
assert_equal 0
[
r lpushx xlist a
]
assert_equal 0
[
r llen xlist
]
assert_equal 0
[
r rpushx xlist a
]
assert_equal 1
[
r rpush xlist b
]
assert_equal 2
[
r rpush xlist c
]
assert_equal 0
[
r llen xlist
]
}
foreach type
{
ziplist list
}
{
test
"LPUSHX, RPUSHX -
$type
"
{
create_$type xlist
{
b c
}
assert_equal 3
[
r rpushx xlist d
]
assert_equal 4
[
r lpushx xlist a
]
assert_encoding ziplist xlist
assert_equal
{
a b c d
}
[
r lrange xlist 0 10
]
assert_equal
{
a b c d
}
[
r lrange xlist 0 -1
]
}
test
"LINSERT -
$type
"
{
create_$type xlist
{
a b c d
}
assert_equal 5
[
r linsert xlist before c zz
]
assert_equal
{
a b zz c d
}
[
r lrange xlist 0 10
]
assert_equal 6
[
r linsert xlist after c yy
]
...
...
@@ -73,61 +106,59 @@ start_server {
assert_equal 8
[
r linsert xlist before a aa
]
assert_equal 8
[
r linsert xlist before bad aaa
]
assert_equal
{
aa a b zz c yy d dd
}
[
r lrange xlist 0 10
]
# check inserting integer encoded value
assert_equal 9
[
r linsert xlist before aa 42
]
assert_equal 42
[
r lrange xlist 0 0
]
}
}
test
{
LPUSHX, RPUSHX
, LPUSHXAFTER, RPUSHXAFTER - regular
list
}
{
test
{
LPUSHX, RPUSHX
convert from ziplist to
list
}
{
set large_value
"aaaaaaaaaaaaaaaaa"
r del xlist
assert_equal 0
[
r lpushx xlist a
]
assert_equal 0
[
r rpushx xlist a
]
assert_equal 1
[
r rpush xlist $large_value
]
assert_equal 2
[
r rpush xlist c
]
assert_equal 3
[
r rpushx xlist d
]
assert_equal 4
[
r lpushx xlist a
]
# convert when a large value is pushed
create_ziplist xlist a
assert_equal 2
[
r rpushx xlist $large_value
]
assert_encoding list xlist
create_ziplist xlist a
assert_equal 2
[
r lpushx xlist $large_value
]
assert_encoding list xlist
assert_equal
{
a aaaaaaaaaaaaaaaaa c d
}
[
r lrange xlist 0 10
]
assert_equal 5
[
r linsert xlist before c zz
]
assert_equal
{
a aaaaaaaaaaaaaaaaa zz c d
}
[
r lrange xlist 0 10
]
assert_equal 6
[
r linsert xlist after c yy
]
assert_equal
{
a aaaaaaaaaaaaaaaaa zz c yy d
}
[
r lrange xlist 0 10
]
assert_equal 7
[
r linsert xlist after d dd
]
assert_equal 7
[
r linsert xlist after bad ddd
]
assert_equal
{
a aaaaaaaaaaaaaaaaa zz c yy d dd
}
[
r lrange xlist 0 10
]
assert_equal 8
[
r linsert xlist before a aa
]
assert_equal 8
[
r linsert xlist before bad aaa
]
assert_equal
{
aa a aaaaaaaaaaaaaaaaa zz c yy d dd
}
[
r lrange xlist 0 10
]
assert_equal 9
[
r linsert xlist before aa 42
]
assert_equal 42
[
r lrange xlist 0 0
]
# convert when the length threshold is exceeded
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal 257
[
r rpushx xlist b
]
assert_encoding list xlist
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal 257
[
r lpushx xlist b
]
assert_encoding list xlist
}
test
{
DEL a list - ziplist
}
{
assert_equal 1
[
r del myziplist2
]
assert_equal 0
[
r exists myziplist2
]
assert_equal 0
[
r llen myziplist2
]
}
test
{
LINSERT convert from ziplist to list
}
{
set large_value
"aaaaaaaaaaaaaaaaa"
test
{
DEL a list - regular list
}
{
assert_equal 1
[
r del mylist2
]
assert_equal 0
[
r exists mylist2
]
assert_equal 0
[
r llen mylist2
]
}
# convert when a large value is inserted
create_ziplist xlist a
assert_equal 2
[
r linsert xlist before a $large_value
]
assert_encoding list xlist
create_ziplist xlist a
assert_equal 2
[
r linsert xlist after a $large_value
]
assert_encoding list xlist
proc create_ziplist
{
key entries
}
{
r del $key
foreach entry $entries
{
r rpush $key $entry
}
assert_encoding ziplist $key
}
# convert when the length threshold is exceeded
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal 257
[
r linsert xlist before a a
]
assert_encoding list xlist
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal 257
[
r linsert xlist after a a
]
assert_encoding list xlist
proc create_list
{
key entries
}
{
r del $key
r rpush $key
"aaaaaaaaaaaaaaaaa"
foreach entry $entries
{
r rpush $key $entry
}
assert_equal
"aaaaaaaaaaaaaaaaa"
[
r lpop $key
]
assert_encoding list $key
# don't convert when the value could not be inserted
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal 256
[
r linsert xlist before foo a
]
assert_encoding ziplist xlist
create_ziplist xlist
[
lrepeat 256 a
]
assert_equal 256
[
r linsert xlist after foo a
]
assert_encoding ziplist xlist
}
foreach
{
type num
}
{
ziplist 250 list 500
}
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录