Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
f65c8f65
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,发现更多精彩内容 >>
提交
f65c8f65
编写于
7月 28, 2011
作者:
A
antirez
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/unstable' into unstable
上级
4bb1ccc6
64f201c2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
125 addition
and
1 deletion
+125
-1
src/networking.c
src/networking.c
+3
-0
tests/support/test.tcl
tests/support/test.tcl
+1
-1
tests/test_helper.tcl
tests/test_helper.tcl
+1
-0
tests/unit/maxmemory.tcl
tests/unit/maxmemory.tcl
+120
-0
未找到文件。
src/networking.c
浏览文件 @
f65c8f65
...
...
@@ -793,6 +793,9 @@ int processMultibulkBuffer(redisClient *c) {
void
processInputBuffer
(
redisClient
*
c
)
{
/* Keep processing while there is something in the input buffer */
while
(
sdslen
(
c
->
querybuf
))
{
/* Immediately abort if the client is in the middle of something. */
if
(
c
->
flags
&
REDIS_BLOCKED
)
return
;
/* REDIS_CLOSE_AFTER_REPLY closes the connection once the reply is
* written to the client. Make sure to not let the reply grow after
* this flag has been set (i.e. don't process more commands). */
...
...
tests/support/test.tcl
浏览文件 @
f65c8f65
...
...
@@ -5,7 +5,7 @@ set ::tests_failed {}
proc assert
{
condition
}
{
if
{
!
[
uplevel 1 expr $condition
]}
{
error
"assertion:Expected
'
$value
' to be true"
error
"assertion:Expected
condition '
$condition
' to be true"
}
}
...
...
tests/test_helper.tcl
浏览文件 @
f65c8f65
...
...
@@ -32,6 +32,7 @@ set ::all_tests {
unit/pubsub
unit/slowlog
unit/scripting
unit/maxmemory
}
# Index to the next test to run in the ::all_tests list.
set ::next_test 0
...
...
tests/unit/maxmemory.tcl
0 → 100644
浏览文件 @
f65c8f65
start_server
{
tags
{
"maxmemory"
}}
{
foreach policy
{
allkeys-random allkeys-lru volatile-lru volatile-random volatile-ttl
}
{
test
"maxmemory - is the memory limit honoured? (policy
$policy
)"
{
# make sure to start with a blank instance
r flushall
# Get the current memory limit and calculate a new limit.
# We just add 100k to the current memory size so that it is
# fast for us to reach that limit.
set used
[
s used_memory
]
set limit
[
expr
{
$used
+100*1024
}]
r config set maxmemory $limit
r config set maxmemory-policy $policy
# Now add keys until the limit is almost reached.
set numkeys 0
while 1
{
r setex
[
randomKey
]
10000 x
incr numkeys
if
{[
s used_memory
]
+4096 > $limit
}
{
assert
{
$numkeys
> 10
}
break
}
}
# If we add the same number of keys already added again, we
# should still be under the limit.
for
{
set j 0
}
{
$j
< $numkeys
}
{
incr j
}
{
r setex
[
randomKey
]
10000 x
}
assert
{[
s used_memory
]
<
(
$limit
+4096
)}
}
}
foreach policy
{
allkeys-random allkeys-lru volatile-lru volatile-random volatile-ttl
}
{
test
"maxmemory - only allkeys-* should remove non-volatile keys (
$policy
)"
{
# make sure to start with a blank instance
r flushall
# Get the current memory limit and calculate a new limit.
# We just add 100k to the current memory size so that it is
# fast for us to reach that limit.
set used
[
s used_memory
]
set limit
[
expr
{
$used
+100*1024
}]
r config set maxmemory $limit
r config set maxmemory-policy $policy
# Now add keys until the limit is almost reached.
set numkeys 0
while 1
{
r set
[
randomKey
]
x
incr numkeys
if
{[
s used_memory
]
+4096 > $limit
}
{
assert
{
$numkeys
> 10
}
break
}
}
# If we add the same number of keys already added again and
# the policy is allkeys-* we should still be under the limit.
# Otherwise we should see an error reported by Redis.
set err 0
for
{
set j 0
}
{
$j
< $numkeys
}
{
incr j
}
{
if
{[
catch
{
r set
[
randomKey
]
x
}
e
]}
{
if
{[
string match
{
*used memory*
}
$e
]}
{
set err 1
}
}
}
if
{[
string match allkeys-* $policy
]}
{
assert
{[
s used_memory
]
<
(
$limit
+4096
)}
}
else
{
assert
{
$err
== 1
}
}
}
}
foreach policy
{
volatile-lru volatile-random volatile-ttl
}
{
test
"maxmemory - policy
$policy
should only remove volatile keys."
{
# make sure to start with a blank instance
r flushall
# Get the current memory limit and calculate a new limit.
# We just add 100k to the current memory size so that it is
# fast for us to reach that limit.
set used
[
s used_memory
]
set limit
[
expr
{
$used
+100*1024
}]
r config set maxmemory $limit
r config set maxmemory-policy $policy
# Now add keys until the limit is almost reached.
set numkeys 0
while 1
{
# Odd keys are volatile
# Even keys are non volatile
if
{
$numkeys
% 2
}
{
r setex
"key:
$numkeys
"
10000 x
}
else
{
r set
"key:
$numkeys
"
x
}
if
{[
s used_memory
]
+4096 > $limit
}
{
assert
{
$numkeys
> 10
}
break
}
incr numkeys
}
# Now we add the same number of volatile keys already added.
# We expect Redis to evict only volatile keys in order to make
# space.
set err 0
for
{
set j 0
}
{
$j
< $numkeys
}
{
incr j
}
{
catch
{
r setex
"foo:
$j
"
10000 x
}
}
# We should still be under the limit.
assert
{[
s used_memory
]
<
(
$limit
+4096
)}
# However all our non volatile keys should be here.
for
{
set j 0
}
{
$j
< $numkeys
}
{
incr j 2
}
{
assert
{[
r exists
"key:
$j
"
]}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录