Commit 4d5a4e4b authored by Wen Hui's avatar Wen Hui Committed by Oran Agra
Browse files

Fix command BITFIELD_RO and BITFIELD argument json file, add some test cases for them (#11445)

According to the source code, the commands can be executed with only key name,
and no GET/SET/INCR operation arguments.
change the docs to reflect that by marking these arguments as optional.
also add tests.

(cherry picked from commit fea9bbbe)
parent 1c75ab06
...@@ -102,7 +102,7 @@ struct redisCommandArg BITFIELD_operation_Subargs[] = { ...@@ -102,7 +102,7 @@ struct redisCommandArg BITFIELD_operation_Subargs[] = {
/* BITFIELD argument table */ /* BITFIELD argument table */
struct redisCommandArg BITFIELD_Args[] = { struct redisCommandArg BITFIELD_Args[] = {
{"key",ARG_TYPE_KEY,0,NULL,NULL,NULL,CMD_ARG_NONE}, {"key",ARG_TYPE_KEY,0,NULL,NULL,NULL,CMD_ARG_NONE},
{"operation",ARG_TYPE_ONEOF,-1,NULL,NULL,NULL,CMD_ARG_MULTIPLE,.subargs=BITFIELD_operation_Subargs}, {"operation",ARG_TYPE_ONEOF,-1,NULL,NULL,NULL,CMD_ARG_OPTIONAL|CMD_ARG_MULTIPLE,.subargs=BITFIELD_operation_Subargs},
{0} {0}
}; };
...@@ -124,7 +124,7 @@ struct redisCommandArg BITFIELD_RO_encoding_offset_Subargs[] = { ...@@ -124,7 +124,7 @@ struct redisCommandArg BITFIELD_RO_encoding_offset_Subargs[] = {
/* BITFIELD_RO argument table */ /* BITFIELD_RO argument table */
struct redisCommandArg BITFIELD_RO_Args[] = { struct redisCommandArg BITFIELD_RO_Args[] = {
{"key",ARG_TYPE_KEY,0,NULL,NULL,NULL,CMD_ARG_NONE}, {"key",ARG_TYPE_KEY,0,NULL,NULL,NULL,CMD_ARG_NONE},
{"encoding_offset",ARG_TYPE_BLOCK,-1,"GET",NULL,NULL,CMD_ARG_MULTIPLE|CMD_ARG_MULTIPLE_TOKEN,.subargs=BITFIELD_RO_encoding_offset_Subargs}, {"encoding_offset",ARG_TYPE_BLOCK,-1,"GET",NULL,NULL,CMD_ARG_OPTIONAL|CMD_ARG_MULTIPLE|CMD_ARG_MULTIPLE_TOKEN,.subargs=BITFIELD_RO_encoding_offset_Subargs},
{0} {0}
}; };
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
"name": "operation", "name": "operation",
"type": "oneof", "type": "oneof",
"multiple": true, "multiple": true,
"optional": true,
"arguments": [ "arguments": [
{ {
"token": "GET", "token": "GET",
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
"token": "GET", "token": "GET",
"name": "encoding_offset", "name": "encoding_offset",
"type": "block", "type": "block",
"optional": true,
"multiple": true, "multiple": true,
"multiple_token": true, "multiple_token": true,
"arguments": [ "arguments": [
......
...@@ -17,6 +17,22 @@ start_server {tags {"bitops"}} { ...@@ -17,6 +17,22 @@ start_server {tags {"bitops"}} {
set results set results
} {0 255 100} } {0 255 100}
test {BITFIELD signed SET and GET together} {
r del bits
set results [r bitfield bits set i8 0 255 set i8 0 100 get i8 0]
} {0 -1 100}
test {BITFIELD unsigned with SET, GET and INCRBY arguments} {
r del bits
set results [r bitfield bits set u8 0 255 incrby u8 0 100 get u8 0]
} {0 99 99}
test {BITFIELD with only key as argument} {
r del bits
set result [r bitfield bits]
assert {$result eq {}}
}
test {BITFIELD #<idx> form} { test {BITFIELD #<idx> form} {
r del bits r del bits
set results {} set results {}
...@@ -224,6 +240,11 @@ start_server {tags {"repl external:skip"}} { ...@@ -224,6 +240,11 @@ start_server {tags {"repl external:skip"}} {
assert_equal 100 [$slave bitfield_ro bits get u8 0] assert_equal 100 [$slave bitfield_ro bits get u8 0]
} }
test {BITFIELD_RO with only key as argument} {
set res [$slave bitfield_ro bits]
assert {$res eq {}}
}
test {BITFIELD_RO fails when write option is used} { test {BITFIELD_RO fails when write option is used} {
catch {$slave bitfield_ro bits set u8 0 100 get u8 0} err catch {$slave bitfield_ro bits set u8 0 100 get u8 0} err
assert_match {*ERR BITFIELD_RO only supports the GET subcommand*} $err assert_match {*ERR BITFIELD_RO only supports the GET subcommand*} $err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment