Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
b0d1d268
Commit
b0d1d268
authored
Jun 13, 2011
by
Pieter Noordhuis
Committed by
antirez
Jun 20, 2011
Browse files
SETNX regression tests.
parent
f85cd526
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/unit/basic.tcl
View file @
b0d1d268
...
@@ -138,21 +138,48 @@ start_server {tags {"basic"}} {
...
@@ -138,21 +138,48 @@ start_server {tags {"basic"}} {
r decrby novar 17179869185
r decrby novar 17179869185
}
{
-1
}
}
{
-1
}
test
{
SETNX target key missing
}
{
test
"SETNX target key missing"
{
r setnx novar2 foobared
r del novar
r get novar2
assert_equal 1
[
r setnx novar foobared
]
}
{
foobared
}
assert_equal
"foobared"
[
r get novar
]
}
test
{
SETNX target key exists
}
{
test
"SETNX target key exists"
{
r setnx novar2 blabla
r set novar foobared
r get novar2
assert_equal 0
[
r setnx novar blabla
]
}
{
foobared
}
assert_equal
"foobared"
[
r get novar
]
}
test
{
SETNX against volatile key
}
{
test
"
SETNX against
not-expired
volatile key
"
{
r set x 10
r set x 10
r expire x 10000
r expire x 10000
list
[
r setnx x 20
]
[
r get x
]
assert_equal 0
[
r setnx x 20
]
}
{
0 10
}
assert_equal 10
[
r get x
]
}
test
"SETNX against expired volatile key"
{
# Make it very unlikely for the key this test uses to be expired by the
# active expiry cycle. This is tightly coupled to the implementation of
# active expiry and dbAdd
()
but currently the only way to test that
# SETNX expires a key when it should have been.
for
{
set x 0
}
{
$x
< 9999
}
{
incr x
}
{
r setex key-$x 3600 value
}
# This will be one of 10000 expiring keys. A cycle is executed every
# 100ms, sampling 10 keys for being expired or not. This key will be
# expired for at most 1s when we wait 2s, resulting in a total sample
# of 100 keys. The probability of the success of this test being a
# false positive is therefore approx. 1%.
r set x 10
r expire x 1
# Wait for the key to expire
after 2000
assert_equal 1
[
r setnx x 20
]
assert_equal 20
[
r get x
]
}
test
{
EXISTS
}
{
test
{
EXISTS
}
{
set res
{}
set res
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment