Unverified Commit 03cd525f authored by debing.sun's avatar debing.sun Committed by GitHub
Browse files

Fix reply schema for hfe related commands (#13238)

parent c33c91db
...@@ -46,24 +46,26 @@ ...@@ -46,24 +46,26 @@
"type": "array", "type": "array",
"minItems": 1, "minItems": 1,
"maxItems": 4294967295, "maxItems": 4294967295,
"items": [ "items": {
{ "oneOf": [
"description": "The field does not exist.", {
"const": -2 "description": "The field does not exist.",
}, "const": -2
{ },
"description": "Specified NX | XX | GT | LT condition not met", {
"const": 0 "description": "Specified NX | XX | GT | LT condition not met",
}, "const": 0
{ },
"description": "Expiration time was set or updated.", {
"const": 1 "description": "Expiration time was set or updated.",
}, "const": 1
{ },
"description": "Field deleted because the specified expiration time is in the past.", {
"const": 2 "description": "Field deleted because the specified expiration time is in the past.",
} "const": 2
] }
]
}
} }
] ]
}, },
......
...@@ -46,24 +46,26 @@ ...@@ -46,24 +46,26 @@
"type": "array", "type": "array",
"minItems": 1, "minItems": 1,
"maxItems": 4294967295, "maxItems": 4294967295,
"items": [ "items": {
{ "oneOf": [
"description": "The field does not exist.", {
"const": -2 "description": "The field does not exist.",
}, "const": -2
{ },
"description": "Specified NX | XX | GT | LT condition not met", {
"const": 0 "description": "Specified NX | XX | GT | LT condition not met",
}, "const": 0
{ },
"description": "Expiration time was set or updated.", {
"const": 1 "description": "Expiration time was set or updated.",
}, "const": 1
{ },
"description": "Field deleted because the specified expiration time is in the past.", {
"const": 2 "description": "Field deleted because the specified expiration time is in the past.",
} "const": 2
] }
]
}
} }
] ]
}, },
......
{ {
"HEXPIRETIME": { "HEXPIRETIME": {
"summary": "Returns the expiration time of a hash field as a Unix timestamp, in seconds.", "summary": "Returns the expiration time of a hash field as a Unix timestamp, in seconds.",
"complexity": "O(N) where N is the number of arguments to the command", "complexity": "O(N) where N is the number of arguments to the command",
"group": "hash", "group": "hash",
"since": "8.0.0", "since": "8.0.0",
"arity": -4, "arity": -4,
"function": "hexpiretimeCommand", "function": "hexpiretimeCommand",
"history": [], "history": [],
"command_flags": [ "command_flags": [
"READONLY", "READONLY",
"FAST" "FAST"
], ],
"acl_categories": [ "acl_categories": [
"HASH" "HASH"
], ],
"key_specs": [ "key_specs": [
{ {
"flags": [ "flags": [
"RO", "RO",
"ACCESS" "ACCESS"
], ],
"begin_search": { "begin_search": {
"index": { "index": {
"pos": 1 "pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
} }
}, ],
"find_keys": { "reply_schema": {
"range": { "oneOf": [
"lastkey": 0, {
"step": 1, "description": "Key does not exist.",
"limit": 0 "type": "null"
} },
} {
} "description": "Array of results",
], "type": "array",
"reply_schema": { "minItems": 1,
"oneOf": [ "maxItems": 4294967295,
{ "items": {
"description": "Key does not exist.", "oneOf": [
"type": "null" {
}, "description": "The field does not exist.",
{ "const": -2
"description": "Array of results", },
"type": "array", {
"minItems": 1, "description": "The field exists but has no associated expire.",
"maxItems": 4294967295, "const": -1
"items": [ },
{ {
"description": "The field does not exist.", "description": "Expiration Unix timestamp in seconds.",
"const": -2 "type": "integer",
}, "minimum": 1
{ }
"description": "The field exists but has no associated expire.", ]
"const": -1 }
}, }
{
"description": "Expiration Unix timestamp in seconds.",
"type": "integer",
"minimum": 1
}
] ]
} },
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "numfields",
"type": "integer"
},
{
"name": "field",
"type": "string",
"multiple": true
}
] ]
},
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "numfields",
"type": "integer"
},
{
"name": "field",
"type": "string",
"multiple": true
}
]
} }
} }
{ {
"HPERSIST": { "HPERSIST": {
"summary": "Removes the expiration time for each specified field", "summary": "Removes the expiration time for each specified field",
"complexity": "O(N) where N is the number of arguments to the command", "complexity": "O(N) where N is the number of arguments to the command",
"group": "hash", "group": "hash",
"since": "8.0.0", "since": "8.0.0",
"arity": -4, "arity": -4,
"function": "hpersistCommand", "function": "hpersistCommand",
"history": [], "history": [],
"command_flags": [ "command_flags": [
"READONLY", "READONLY",
"FAST" "FAST"
], ],
"acl_categories": [ "acl_categories": [
"HASH" "HASH"
], ],
"key_specs": [ "key_specs": [
{ {
"flags": [ "flags": [
"RO", "RO",
"ACCESS" "ACCESS"
], ],
"begin_search": { "begin_search": {
"index": { "index": {
"pos": 1 "pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
} }
}, ],
"find_keys": { "reply_schema": {
"range": { "oneOf": [
"lastkey": 0, {
"step": 1, "description": "Key does not exist.",
"limit": 0 "type": "null"
} },
} {
} "description": "Array of results",
], "type": "array",
"reply_schema": { "minItems": 1,
"oneOf": [ "maxItems": 4294967295,
{ "items": {
"description": "Key does not exist.", "oneOf": [
"type": "null" {
}, "description": "The field does not exist.",
{ "const": -2
"description": "Array of results", },
"type": "array", {
"minItems": 1, "description": "The field exists but has no associated expire.",
"maxItems": 4294967295, "const": -1
"items": [ },
{ {
"description": "The field does not exist.", "description": "Expiration time was removed",
"const": -2 "const": 1
}, }
{ ]
"description": "The field exists but has no associated expire.", }
"const": -1 }
},
{
"description": "Expiration time was removed",
"const": 1
}
] ]
} },
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "numfields",
"type": "integer"
},
{
"name": "field",
"type": "string",
"multiple": true
}
] ]
},
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "numfields",
"type": "integer"
},
{
"name": "field",
"type": "string",
"multiple": true
}
]
} }
} }
...@@ -46,24 +46,26 @@ ...@@ -46,24 +46,26 @@
"type": "array", "type": "array",
"minItems": 1, "minItems": 1,
"maxItems": 4294967295, "maxItems": 4294967295,
"items": [ "items": {
{ "oneOf": [
"description": "The field does not exist.", {
"const": -2 "description": "The field does not exist.",
}, "const": -2
{ },
"description": "Specified NX | XX | GT | LT condition not met", {
"const": 0 "description": "Specified NX | XX | GT | LT condition not met",
}, "const": 0
{ },
"description": "Expiration time was set or updated.", {
"const": 1 "description": "Expiration time was set or updated.",
}, "const": 1
{ },
"description": "Field deleted because the specified expiration time is in the past.", {
"const": 2 "description": "Field deleted because the specified expiration time is in the past.",
} "const": 2
] }
]
}
} }
] ]
}, },
......
...@@ -46,24 +46,26 @@ ...@@ -46,24 +46,26 @@
"type": "array", "type": "array",
"minItems": 1, "minItems": 1,
"maxItems": 4294967295, "maxItems": 4294967295,
"items": [ "items": {
{ "oneOf": [
"description": "The field does not exist.", {
"const": -2 "description": "The field does not exist.",
}, "const": -2
{ },
"description": "Specified NX | XX | GT | LT condition not met", {
"const": 0 "description": "Specified NX | XX | GT | LT condition not met",
}, "const": 0
{ },
"description": "Expiration time was set or updated.", {
"const": 1 "description": "Expiration time was set or updated.",
}, "const": 1
{ },
"description": "Field deleted because the specified expiration time is in the past.", {
"const": 2 "description": "Field deleted because the specified expiration time is in the past.",
} "const": 2
] }
]
}
} }
] ]
}, },
......
{ {
"HPEXPIRETIME": { "HPEXPIRETIME": {
"summary": "Returns the expiration time of a hash field as a Unix timestamp, in msec.", "summary": "Returns the expiration time of a hash field as a Unix timestamp, in msec.",
"complexity": "O(N) where N is the number of arguments to the command", "complexity": "O(N) where N is the number of arguments to the command",
"group": "hash", "group": "hash",
"since": "8.0.0", "since": "8.0.0",
"arity": -4, "arity": -4,
"function": "hpexpiretimeCommand", "function": "hpexpiretimeCommand",
"history": [], "history": [],
"command_flags": [ "command_flags": [
"READONLY", "READONLY",
"FAST" "FAST"
], ],
"acl_categories": [ "acl_categories": [
"HASH" "HASH"
], ],
"key_specs": [ "key_specs": [
{ {
"flags": [ "flags": [
"RO", "RO",
"ACCESS" "ACCESS"
], ],
"begin_search": { "begin_search": {
"index": { "index": {
"pos": 1 "pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
} }
}, ],
"find_keys": { "reply_schema": {
"range": { "oneOf": [
"lastkey": 0, {
"step": 1, "description": "Key does not exist.",
"limit": 0 "type": "null"
} },
} {
} "description": "The keyname, popped member, and its score.",
], "type": "array",
"reply_schema": { "minItems": 1,
"oneOf": [ "maxItems": 4294967295,
{ "items": {
"description": "Key does not exist.", "oneOf": [
"type": "null" {
}, "description": "The field does not exist.",
{ "const": -2
"description": "The keyname, popped member, and its score.", },
"type": "array", {
"minItems": 1, "description": "The field exists but has no associated expire.",
"maxItems": 4294967295, "const": -1
"items": [ },
{ {
"description": "The field does not exist.", "description": "Expiration Unix timestamp in milliseconds.",
"const": -2 "type": "integer",
}, "minimum": 1
{ }
"description": "The field exists but has no associated expire.", ]
"const": -1 }
}, }
{
"description": "Expiration Unix timestamp in milliseconds.",
"type": "integer",
"minimum": 1
}
] ]
} },
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "numfields",
"type": "integer"
},
{
"name": "field",
"type": "string",
"multiple": true
}
] ]
},
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "numfields",
"type": "integer"
},
{
"name": "field",
"type": "string",
"multiple": true
}
]
} }
} }
{ {
"HPTTL": { "HPTTL": {
"summary": "Returns the TTL in milliseconds of a hash field.", "summary": "Returns the TTL in milliseconds of a hash field.",
"complexity": "O(N) where N is the number of arguments to the command", "complexity": "O(N) where N is the number of arguments to the command",
"group": "hash", "group": "hash",
"since": "8.0.0", "since": "8.0.0",
"arity": -4, "arity": -4,
"function": "hpttlCommand", "function": "hpttlCommand",
"history": [], "history": [],
"command_flags": [ "command_flags": [
"READONLY", "READONLY",
"FAST" "FAST"
], ],
"acl_categories": [ "acl_categories": [
"HASH" "HASH"
], ],
"key_specs": [ "key_specs": [
{ {
"flags": [ "flags": [
"RO", "RO",
"ACCESS" "ACCESS"
], ],
"begin_search": { "begin_search": {
"index": { "index": {
"pos": 1 "pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
} }
}, ],
"find_keys": { "reply_schema": {
"range": { "oneOf": [
"lastkey": 0, {
"step": 1, "description": "Key does not exist.",
"limit": 0 "type": "null"
} },
} {
} "description": "The keyname, popped member, and its score.",
], "type": "array",
"reply_schema": { "minItems": 1,
"oneOf": [ "maxItems": 4294967295,
{ "items": {
"description": "Key does not exist.", "oneOf": [
"type": "null" {
}, "description": "The field does not exist.",
{ "const": -2
"description": "The keyname, popped member, and its score.", },
"type": "array", {
"minItems": 1, "description": "The field exists but has no associated expire.",
"maxItems": 4294967295, "const": -1
"items": [ },
{ {
"description": "The field does not exist.", "description": "TTL in milliseconds.",
"const": -2 "type": "integer",
}, "minimum": 1
{ }
"description": "The field exists but has no associated expire.", ]
"const": -1 }
}, }
{
"description": "TTL in milliseconds.",
"type": "integer",
"minimum": 1
}
] ]
} },
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "numfields",
"type": "integer"
},
{
"name": "field",
"type": "string",
"multiple": true
}
] ]
},
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "numfields",
"type": "integer"
},
{
"name": "field",
"type": "string",
"multiple": true
}
]
} }
} }
{ {
"HTTL": { "HTTL": {
"summary": "Returns the TTL in seconds of a hash field.", "summary": "Returns the TTL in seconds of a hash field.",
"complexity": "O(N) where N is the number of arguments to the command", "complexity": "O(N) where N is the number of arguments to the command",
"group": "hash", "group": "hash",
"since": "8.0.0", "since": "8.0.0",
"arity": -4, "arity": -4,
"function": "httlCommand", "function": "httlCommand",
"history": [], "history": [],
"command_flags": [ "command_flags": [
"READONLY", "READONLY",
"FAST" "FAST"
], ],
"acl_categories": [ "acl_categories": [
"HASH" "HASH"
], ],
"key_specs": [ "key_specs": [
{ {
"flags": [ "flags": [
"RO", "RO",
"ACCESS" "ACCESS"
], ],
"begin_search": { "begin_search": {
"index": { "index": {
"pos": 1 "pos": 1
}
},
"find_keys": {
"range": {
"lastkey": 0,
"step": 1,
"limit": 0
}
}
} }
}, ],
"find_keys": { "reply_schema": {
"range": { "oneOf": [
"lastkey": 0, {
"step": 1, "description": "Key does not exist.",
"limit": 0 "type": "null"
} },
} {
} "description": "Array of results",
], "type": "array",
"reply_schema": { "minItems": 1,
"oneOf": [ "maxItems": 4294967295,
{ "items": {
"description": "Key does not exist.", "oneOf": [
"type": "null" {
}, "description": "The field does not exist.",
{ "const": -2
"description": "Array of results", },
"type": "array", {
"minItems": 1, "description": "The field exists but has no associated expire.",
"maxItems": 4294967295, "const": -1
"items": [ },
{ {
"description": "The field does not exist.", "description": "TTL in seconds.",
"const": -2 "type": "integer",
}, "minimum": 1
{ }
"description": "The field exists but has no associated expire.", ]
"const": -1 }
}, }
{
"description": "TTL in seconds.",
"type": "integer",
"minimum": 1
}
] ]
} },
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "numfields",
"type": "integer"
},
{
"name": "field",
"type": "string",
"multiple": true
}
] ]
},
"arguments": [
{
"name": "key",
"type": "key",
"key_spec_index": 0
},
{
"name": "numfields",
"type": "integer"
},
{
"name": "field",
"type": "string",
"multiple": true
}
]
} }
} }
...@@ -88,41 +88,63 @@ start_server {tags {"external:skip needs:debug"}} { ...@@ -88,41 +88,63 @@ start_server {tags {"external:skip needs:debug"}} {
# Currently listpack doesn't support HFE # Currently listpack doesn't support HFE
r config set hash-max-listpack-entries 0 r config set hash-max-listpack-entries 0
test {HPEXPIRE - Test 'NX' flag} { test {HPEXPIRE(AT) - Test 'NX' flag} {
r del myhash r del myhash
r hset myhash field1 value1 field2 value2 field3 value3 r hset myhash field1 value1 field2 value2 field3 value3
assert_equal [r hpexpire myhash 1000 NX 1 field1] [list $E_OK] assert_equal [r hpexpire myhash 1000 NX 1 field1] [list $E_OK]
assert_equal [r hpexpire myhash 1000 NX 2 field1 field2] [list $E_FAIL $E_OK] assert_equal [r hpexpire myhash 1000 NX 2 field1 field2] [list $E_FAIL $E_OK]
r del myhash
r hset myhash field1 value1 field2 value2 field3 value3
assert_equal [r hpexpireat myhash [expr {([clock seconds]+1000)*1000}] NX 1 field1] [list $E_OK]
assert_equal [r hpexpireat myhash [expr {([clock seconds]+1000)*1000}] NX 2 field1 field2] [list $E_FAIL $E_OK]
} }
test {HPEXPIRE - Test 'XX' flag} { test {HPEXPIRE(AT) - Test 'XX' flag} {
r del myhash r del myhash
r hset myhash field1 value1 field2 value2 field3 value3 r hset myhash field1 value1 field2 value2 field3 value3
assert_equal [r hpexpire myhash 1000 NX 2 field1 field2] [list $E_OK $E_OK] assert_equal [r hpexpire myhash 1000 NX 2 field1 field2] [list $E_OK $E_OK]
assert_equal [r hpexpire myhash 1000 XX 2 field1 field3] [list $E_OK $E_FAIL] assert_equal [r hpexpire myhash 1000 XX 2 field1 field3] [list $E_OK $E_FAIL]
r del myhash
r hset myhash field1 value1 field2 value2 field3 value3
assert_equal [r hpexpireat myhash [expr {([clock seconds]+1000)*1000}] NX 2 field1 field2] [list $E_OK $E_OK]
assert_equal [r hpexpireat myhash [expr {([clock seconds]+1000)*1000}] XX 2 field1 field3] [list $E_OK $E_FAIL]
} }
test {HPEXPIRE - Test 'GT' flag} { test {HPEXPIRE(AT) - Test 'GT' flag} {
r del myhash r del myhash
r hset myhash field1 value1 field2 value2 r hset myhash field1 value1 field2 value2
assert_equal [r hpexpire myhash 1000 NX 1 field1] [list $E_OK] assert_equal [r hpexpire myhash 1000 NX 1 field1] [list $E_OK]
assert_equal [r hpexpire myhash 2000 NX 1 field2] [list $E_OK] assert_equal [r hpexpire myhash 2000 NX 1 field2] [list $E_OK]
assert_equal [r hpexpire myhash 1500 GT 2 field1 field2] [list $E_OK $E_FAIL] assert_equal [r hpexpire myhash 1500 GT 2 field1 field2] [list $E_OK $E_FAIL]
r del myhash
r hset myhash field1 value1 field2 value2
assert_equal [r hpexpireat myhash [expr {([clock seconds]+1000)*1000}] NX 1 field1] [list $E_OK]
assert_equal [r hpexpireat myhash [expr {([clock seconds]+2000)*1000}] NX 1 field2] [list $E_OK]
assert_equal [r hpexpireat myhash [expr {([clock seconds]+1500)*1000}] GT 2 field1 field2] [list $E_OK $E_FAIL]
} }
test {HPEXPIRE - Test 'LT' flag} { test {HPEXPIRE(AT) - Test 'LT' flag} {
r del myhash r del myhash
r hset myhash field1 value1 field2 value2 r hset myhash field1 value1 field2 value2
assert_equal [r hpexpire myhash 1000 NX 1 field1] [list $E_OK] assert_equal [r hpexpire myhash 1000 NX 1 field1] [list $E_OK]
assert_equal [r hpexpire myhash 2000 NX 1 field2] [list $E_OK] assert_equal [r hpexpire myhash 2000 NX 1 field2] [list $E_OK]
assert_equal [r hpexpire myhash 1500 LT 2 field1 field2] [list $E_FAIL $E_OK] assert_equal [r hpexpire myhash 1500 LT 2 field1 field2] [list $E_FAIL $E_OK]
r del myhash
r hset myhash field1 value1 field2 value2
assert_equal [r hpexpireat myhash [expr {([clock seconds]+1000)*1000}] NX 1 field1] [list $E_OK]
assert_equal [r hpexpireat myhash [expr {([clock seconds]+2000)*1000}] NX 1 field2] [list $E_OK]
assert_equal [r hpexpireat myhash [expr {([clock seconds]+1500)*1000}] LT 2 field1 field2] [list $E_FAIL $E_OK]
} }
test {HPEXPIREAT - field not exists or TTL is in the past} { test {HPEXPIREAT - field not exists or TTL is in the past} {
r del myhash r del myhash
r hset myhash f1 v1 f2 v2 f4 v4 r hset myhash f1 v1 f2 v2 f4 v4
r hexpire myhash 1000 NX 1 f4 r hexpire myhash 1000 NX 1 f4
assert_equal [r hexpireat myhash [expr {[clock seconds] - 1}] NX 4 f1 f2 f3 f4] "$E_DELETED $E_DELETED $E_NO_FIELD $E_FAIL" assert_equal [r hpexpireat myhash [expr {([clock seconds]-1)*1000}] NX 4 f1 f2 f3 f4] "$E_DELETED $E_DELETED $E_NO_FIELD $E_FAIL"
assert_equal [r hexists myhash field1] 0 assert_equal [r hexists myhash field1] 0
} }
......
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