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
910e72d1
Commit
910e72d1
authored
May 29, 2015
by
antirez
Browse files
Test: ZADD NX and XX options tests
parent
c043a4e6
Changes
1
Show whitespace changes
Inline
Side-by-side
tests/unit/type/zset.tcl
View file @
910e72d1
...
...
@@ -43,6 +43,63 @@ start_server {tags {"zset"}} {
assert_error
"*not*float*"
{
r zadd myzset nan abc
}
}
test
"ZADD with options syntax error with incomplete pair"
{
r del ztmp
catch
{
r zadd ztmp xx 10 x 20
}
err
set err
}
{
ERR*
}
test
"ZADD XX option without key -
$encoding
"
{
r del ztmp
assert
{[
r zadd ztmp xx 10 x
]
== 0
}
assert
{[
r type ztmp
]
eq
{
none
}}
}
test
"ZADD XX existing key -
$encoding
"
{
r del ztmp
r zadd ztmp 10 x
assert
{[
r zadd ztmp xx 20 y
]
== 0
}
assert
{[
r zcard ztmp
]
== 1
}
}
test
"ZADD XX returns the number of elements actually added"
{
r del ztmp
r zadd ztmp 10 x
set retval
[
r zadd ztmp 10 x 20 y 30 z
]
assert
{
$retval
== 2
}
}
test
"ZADD XX updates existing elements score"
{
r del ztmp
r zadd ztmp 10 x 20 y 30 z
r zadd ztmp xx 5 foo 11 x 21 y 40 zap
assert
{[
r zcard ztmp
]
== 3
}
assert
{[
r zscore ztmp x
]
== 11
}
assert
{[
r zscore ztmp y
]
== 21
}
}
test
"ZADD XX and NX are not compatible"
{
r del ztmp
catch
{
r zadd ztmp xx nx 10 x
}
err
set err
}
{
ERR*
}
test
"ZADD NX with non exisitng key"
{
r del ztmp
r zadd ztmp nx 10 x 20 y 30 z
assert
{[
r zcard ztmp
]
== 3
}
}
test
"ZADD NX only add new elements without updating old ones"
{
r del ztmp
r zadd ztmp 10 x 20 y 30 z
assert
{[
r zadd ztmp nx 11 x 21 y 100 a 200 b
]
== 2
}
assert
{[
r zscore ztmp x
]
== 10
}
assert
{[
r zscore ztmp y
]
== 20
}
assert
{[
r zscore ztmp a
]
== 100
}
assert
{[
r zscore ztmp b
]
== 200
}
}
test
"ZINCRBY calls leading to NaN result in error"
{
r zincrby myzset +inf abc
assert_error
"*NaN*"
{
r zincrby myzset -inf abc
}
...
...
@@ -77,6 +134,8 @@ start_server {tags {"zset"}} {
}
test
"ZCARD basics -
$encoding
"
{
r del ztmp
r zadd ztmp 10 a 20 b 30 c
assert_equal 3
[
r zcard ztmp
]
assert_equal 0
[
r zcard zdoesntexist
]
}
...
...
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