Type mismatch errors are now prefixed with WRONGTYPE.
So instead to reply with a generic error like: -ERR ... wrong kind of value ... now it replies with: -WRONGTYPE ... wrong kind of value ... This makes this particular error easy to check without resorting to (fragile) pattern matching of the error string (however the error string used to be consistent already). Client libraries should return a specific exeption type for this error. Most of the commit is about fixing unit tests.
This commit is contained in:
parent
06851a93de
commit
c4b0b6854e
@ -1032,7 +1032,7 @@ void createSharedObjects(void) {
|
|||||||
shared.pong = createObject(REDIS_STRING,sdsnew("+PONG\r\n"));
|
shared.pong = createObject(REDIS_STRING,sdsnew("+PONG\r\n"));
|
||||||
shared.queued = createObject(REDIS_STRING,sdsnew("+QUEUED\r\n"));
|
shared.queued = createObject(REDIS_STRING,sdsnew("+QUEUED\r\n"));
|
||||||
shared.wrongtypeerr = createObject(REDIS_STRING,sdsnew(
|
shared.wrongtypeerr = createObject(REDIS_STRING,sdsnew(
|
||||||
"-ERR Operation against a key holding the wrong kind of value\r\n"));
|
"-WRONGTYPE Operation against a key holding the wrong kind of value\r\n"));
|
||||||
shared.nokeyerr = createObject(REDIS_STRING,sdsnew(
|
shared.nokeyerr = createObject(REDIS_STRING,sdsnew(
|
||||||
"-ERR no such key\r\n"));
|
"-ERR no such key\r\n"));
|
||||||
shared.syntaxerr = createObject(REDIS_STRING,sdsnew(
|
shared.syntaxerr = createObject(REDIS_STRING,sdsnew(
|
||||||
|
@ -143,7 +143,7 @@ start_server {tags {"basic"}} {
|
|||||||
catch {r incr mylist} err
|
catch {r incr mylist} err
|
||||||
r rpop mylist
|
r rpop mylist
|
||||||
format $err
|
format $err
|
||||||
} {ERR*}
|
} {WRONGTYPE*}
|
||||||
|
|
||||||
test {DECRBY over 32bit value with over 32bit increment, negative res} {
|
test {DECRBY over 32bit value with over 32bit increment, negative res} {
|
||||||
r set novar 17179869184
|
r set novar 17179869184
|
||||||
@ -201,7 +201,7 @@ start_server {tags {"basic"}} {
|
|||||||
catch {r incrbyfloat mylist 1.0} err
|
catch {r incrbyfloat mylist 1.0} err
|
||||||
r del mylist
|
r del mylist
|
||||||
format $err
|
format $err
|
||||||
} {ERR*kind*}
|
} {WRONGTYPE*}
|
||||||
|
|
||||||
test {INCRBYFLOAT does not allow NaN or Infinity} {
|
test {INCRBYFLOAT does not allow NaN or Infinity} {
|
||||||
r set foo 0
|
r set foo 0
|
||||||
@ -531,7 +531,7 @@ start_server {tags {"basic"}} {
|
|||||||
test "SETBIT against key with wrong type" {
|
test "SETBIT against key with wrong type" {
|
||||||
r del mykey
|
r del mykey
|
||||||
r lpush mykey "foo"
|
r lpush mykey "foo"
|
||||||
assert_error "*wrong kind*" {r setbit mykey 0 1}
|
assert_error "WRONGTYPE*" {r setbit mykey 0 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "SETBIT with out of range bit offset" {
|
test "SETBIT with out of range bit offset" {
|
||||||
@ -665,7 +665,7 @@ start_server {tags {"basic"}} {
|
|||||||
test "SETRANGE against key with wrong type" {
|
test "SETRANGE against key with wrong type" {
|
||||||
r del mykey
|
r del mykey
|
||||||
r lpush mykey "foo"
|
r lpush mykey "foo"
|
||||||
assert_error "*wrong kind*" {r setrange mykey 0 bar}
|
assert_error "WRONGTYPE*" {r setrange mykey 0 bar}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "SETRANGE with out of range offset" {
|
test "SETRANGE with out of range offset" {
|
||||||
|
@ -170,7 +170,7 @@ start_server {tags {"bitops"}} {
|
|||||||
r lpush c foo
|
r lpush c foo
|
||||||
catch {r bitop xor dest a b c d} e
|
catch {r bitop xor dest a b c d} e
|
||||||
set e
|
set e
|
||||||
} {*ERR*}
|
} {WRONGTYPE*}
|
||||||
|
|
||||||
test {BITOP with empty string after non empty string (issue #529)} {
|
test {BITOP with empty string after non empty string (issue #529)} {
|
||||||
r flushdb
|
r flushdb
|
||||||
|
@ -242,7 +242,7 @@ start_server {
|
|||||||
r del blist target
|
r del blist target
|
||||||
r set blist nolist
|
r set blist nolist
|
||||||
$rd brpoplpush blist target 1
|
$rd brpoplpush blist target 1
|
||||||
assert_error "ERR*wrong kind*" {$rd read}
|
assert_error "WRONGTYPE*" {$rd read}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "BRPOPLPUSH with wrong destination type" {
|
test "BRPOPLPUSH with wrong destination type" {
|
||||||
@ -251,7 +251,7 @@ start_server {
|
|||||||
r set target nolist
|
r set target nolist
|
||||||
r lpush blist foo
|
r lpush blist foo
|
||||||
$rd brpoplpush blist target 1
|
$rd brpoplpush blist target 1
|
||||||
assert_error "ERR*wrong kind*" {$rd read}
|
assert_error "WRONGTYPE*" {$rd read}
|
||||||
|
|
||||||
set rd [redis_deferring_client]
|
set rd [redis_deferring_client]
|
||||||
r del blist target
|
r del blist target
|
||||||
@ -259,7 +259,7 @@ start_server {
|
|||||||
$rd brpoplpush blist target 0
|
$rd brpoplpush blist target 0
|
||||||
after 1000
|
after 1000
|
||||||
r rpush blist foo
|
r rpush blist foo
|
||||||
assert_error "ERR*wrong kind*" {$rd read}
|
assert_error "WRONGTYPE*" {$rd read}
|
||||||
assert_equal {foo} [r lrange blist 0 -1]
|
assert_equal {foo} [r lrange blist 0 -1]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ start_server {
|
|||||||
r set target nolist
|
r set target nolist
|
||||||
$rd brpoplpush blist target 0
|
$rd brpoplpush blist target 0
|
||||||
r rpush blist a b c
|
r rpush blist a b c
|
||||||
assert_error "ERR*wrong kind*" {$rd read}
|
assert_error "WRONGTYPE*" {$rd read}
|
||||||
r lrange blist 0 -1
|
r lrange blist 0 -1
|
||||||
} {a b c}
|
} {a b c}
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ start_server {
|
|||||||
$rd2 brpoplpush blist target2 0
|
$rd2 brpoplpush blist target2 0
|
||||||
r lpush blist foo
|
r lpush blist foo
|
||||||
|
|
||||||
assert_error "ERR*wrong kind*" {$rd1 read}
|
assert_error "WRONGTYPE*" {$rd1 read}
|
||||||
assert_equal {foo} [$rd2 read]
|
assert_equal {foo} [$rd2 read]
|
||||||
assert_equal {foo} [r lrange target2 0 -1]
|
assert_equal {foo} [r lrange target2 0 -1]
|
||||||
}
|
}
|
||||||
@ -424,7 +424,7 @@ start_server {
|
|||||||
r del blist1 blist2
|
r del blist1 blist2
|
||||||
r set blist2 nolist
|
r set blist2 nolist
|
||||||
$rd $pop blist1 blist2 1
|
$rd $pop blist1 blist2 1
|
||||||
assert_error "ERR*wrong kind*" {$rd read}
|
assert_error "WRONGTYPE*" {$rd read}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "$pop: timeout" {
|
test "$pop: timeout" {
|
||||||
@ -594,7 +594,7 @@ start_server {
|
|||||||
test {LLEN against non-list value error} {
|
test {LLEN against non-list value error} {
|
||||||
r del mylist
|
r del mylist
|
||||||
r set mylist foobar
|
r set mylist foobar
|
||||||
assert_error ERR* {r llen mylist}
|
assert_error WRONGTYPE* {r llen mylist}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {LLEN against non existing key} {
|
test {LLEN against non existing key} {
|
||||||
@ -602,7 +602,7 @@ start_server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test {LINDEX against non-list value error} {
|
test {LINDEX against non-list value error} {
|
||||||
assert_error ERR* {r lindex mylist 0}
|
assert_error WRONGTYPE* {r lindex mylist 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {LINDEX against non existing key} {
|
test {LINDEX against non existing key} {
|
||||||
@ -610,11 +610,11 @@ start_server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test {LPUSH against non-list value error} {
|
test {LPUSH against non-list value error} {
|
||||||
assert_error ERR* {r lpush mylist 0}
|
assert_error WRONGTYPE* {r lpush mylist 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
test {RPUSH against non-list value error} {
|
test {RPUSH against non-list value error} {
|
||||||
assert_error ERR* {r rpush mylist 0}
|
assert_error WRONGTYPE* {r rpush mylist 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach {type large} [array get largevalue] {
|
foreach {type large} [array get largevalue] {
|
||||||
@ -663,7 +663,7 @@ start_server {
|
|||||||
test {RPOPLPUSH against non list src key} {
|
test {RPOPLPUSH against non list src key} {
|
||||||
r del srclist dstlist
|
r del srclist dstlist
|
||||||
r set srclist x
|
r set srclist x
|
||||||
assert_error ERR* {r rpoplpush srclist dstlist}
|
assert_error WRONGTYPE* {r rpoplpush srclist dstlist}
|
||||||
assert_type string srclist
|
assert_type string srclist
|
||||||
assert_equal 0 [r exists newlist]
|
assert_equal 0 [r exists newlist]
|
||||||
}
|
}
|
||||||
@ -671,7 +671,7 @@ start_server {
|
|||||||
test {RPOPLPUSH against non list dst key} {
|
test {RPOPLPUSH against non list dst key} {
|
||||||
create_ziplist srclist {a b c d}
|
create_ziplist srclist {a b c d}
|
||||||
r set dstlist x
|
r set dstlist x
|
||||||
assert_error ERR* {r rpoplpush srclist dstlist}
|
assert_error WRONGTYPE* {r rpoplpush srclist dstlist}
|
||||||
assert_type string dstlist
|
assert_type string dstlist
|
||||||
assert_equal {a b c d} [r lrange srclist 0 -1]
|
assert_equal {a b c d} [r lrange srclist 0 -1]
|
||||||
}
|
}
|
||||||
@ -697,8 +697,8 @@ start_server {
|
|||||||
|
|
||||||
test {LPOP/RPOP against non list value} {
|
test {LPOP/RPOP against non list value} {
|
||||||
r set notalist foo
|
r set notalist foo
|
||||||
assert_error ERR*kind* {r lpop notalist}
|
assert_error WRONGTYPE* {r lpop notalist}
|
||||||
assert_error ERR*kind* {r rpop notalist}
|
assert_error WRONGTYPE* {r rpop notalist}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach {type num} {ziplist 250 linkedlist 500} {
|
foreach {type num} {ziplist 250 linkedlist 500} {
|
||||||
@ -798,7 +798,7 @@ start_server {
|
|||||||
|
|
||||||
test {LSET against non list value} {
|
test {LSET against non list value} {
|
||||||
r set nolist foobar
|
r set nolist foobar
|
||||||
assert_error ERR*value* {r lset nolist 0 foo}
|
assert_error WRONGTYPE* {r lset nolist 0 foo}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach {type e} [array get largevalue] {
|
foreach {type e} [array get largevalue] {
|
||||||
|
@ -35,7 +35,7 @@ start_server {
|
|||||||
|
|
||||||
test {SADD against non set} {
|
test {SADD against non set} {
|
||||||
r lpush mylist foo
|
r lpush mylist foo
|
||||||
assert_error ERR*kind* {r sadd mylist bar}
|
assert_error WRONGTYPE* {r sadd mylist bar}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "SADD a non-integer against an intset" {
|
test "SADD a non-integer against an intset" {
|
||||||
@ -215,12 +215,12 @@ start_server {
|
|||||||
|
|
||||||
test "SINTER against non-set should throw error" {
|
test "SINTER against non-set should throw error" {
|
||||||
r set key1 x
|
r set key1 x
|
||||||
assert_error "ERR*wrong kind*" {r sinter key1 noset}
|
assert_error "WRONGTYPE*" {r sinter key1 noset}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "SUNION against non-set should throw error" {
|
test "SUNION against non-set should throw error" {
|
||||||
r set key1 x
|
r set key1 x
|
||||||
assert_error "ERR*wrong kind*" {r sunion key1 noset}
|
assert_error "WRONGTYPE*" {r sunion key1 noset}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "SINTER should handle non existing key as empty" {
|
test "SINTER should handle non existing key as empty" {
|
||||||
@ -445,12 +445,12 @@ start_server {
|
|||||||
|
|
||||||
test "SMOVE wrong src key type" {
|
test "SMOVE wrong src key type" {
|
||||||
r set x 10
|
r set x 10
|
||||||
assert_error "ERR*wrong kind*" {r smove x myset2 foo}
|
assert_error "WRONGTYPE*" {r smove x myset2 foo}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "SMOVE wrong dst key type" {
|
test "SMOVE wrong dst key type" {
|
||||||
r set x 10
|
r set x 10
|
||||||
assert_error "ERR*wrong kind*" {r smove myset2 x foo}
|
assert_error "WRONGTYPE*" {r smove myset2 x foo}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "SMOVE with identical source and destination" {
|
test "SMOVE with identical source and destination" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user