1 start_server
{tags
{"maxmemory"}} {
3 allkeys-random allkeys-lru volatile-lru volatile-random volatile-ttl
5 test
"maxmemory - is the memory limit honoured? (policy $policy)" {
6 # make sure to start with a blank instance
8 # Get the current memory limit and calculate a new limit.
9 # We just add 100k to the current memory size so that it is
10 # fast for us to reach that limit.
11 set used
[s used_memory
]
12 set limit
[expr {$used+100*1024}]
13 r config
set maxmemory
$limit
14 r config
set maxmemory-policy
$policy
15 # Now add keys until the limit is almost reached.
18 r setex
[randomKey
] 10000 x
20 if {[s used_memory
]+4096 > $limit} {
21 assert
{$numkeys > 10}
25 # If we add the same number of keys already added again, we
26 # should still be under the limit.
27 for {set j
0} {$j < $numkeys} {incr j
} {
28 r setex
[randomKey
] 10000 x
30 assert
{[s used_memory
] < ($limit+4096)}
35 allkeys-random allkeys-lru volatile-lru volatile-random volatile-ttl
37 test
"maxmemory - only allkeys-* should remove non-volatile keys ($policy)" {
38 # make sure to start with a blank instance
40 # Get the current memory limit and calculate a new limit.
41 # We just add 100k to the current memory size so that it is
42 # fast for us to reach that limit.
43 set used
[s used_memory
]
44 set limit
[expr {$used+100*1024}]
45 r config
set maxmemory
$limit
46 r config
set maxmemory-policy
$policy
47 # Now add keys until the limit is almost reached.
52 if {[s used_memory
]+4096 > $limit} {
53 assert
{$numkeys > 10}
57 # If we add the same number of keys already added again and
58 # the policy is allkeys-* we should still be under the limit.
59 # Otherwise we should see an error reported by Redis.
61 for {set j
0} {$j < $numkeys} {incr j
} {
62 if {[catch {r
set [randomKey
] x
} e
]} {
63 if {[string match
{*used
memory*} $e]} {
68 if {[string match allkeys-
* $policy]} {
69 assert
{[s used_memory
] < ($limit+4096)}
77 volatile-lru volatile-random volatile-ttl
79 test
"maxmemory - policy $policy should only remove volatile keys." {
80 # make sure to start with a blank instance
82 # Get the current memory limit and calculate a new limit.
83 # We just add 100k to the current memory size so that it is
84 # fast for us to reach that limit.
85 set used
[s used_memory
]
86 set limit
[expr {$used+100*1024}]
87 r config
set maxmemory
$limit
88 r config
set maxmemory-policy
$policy
89 # Now add keys until the limit is almost reached.
92 # Odd keys are volatile
93 # Even keys are non volatile
95 r setex
"key:$numkeys" 10000 x
97 r
set "key:$numkeys" x
99 if {[s used_memory
]+4096 > $limit} {
100 assert
{$numkeys > 10}
105 # Now we add the same number of volatile keys already added.
106 # We expect Redis to evict only volatile keys in order to make
109 for {set j
0} {$j < $numkeys} {incr j
} {
110 catch {r setex
"foo:$j" 10000 x
}
112 # We should still be under the limit.
113 assert
{[s used_memory
] < ($limit+4096)}
114 # However all our non volatile keys should be here.
115 for {set j
0} {$j < $numkeys} {incr j
2} {
116 assert
{[r exists
"key:$j"]}