| 1 |
def test_set(judge_command): |
| 2 |
judge_command("SET abc bar", {"command": "SET", "key": "abc", "value": "bar"}) |
| 3 |
judge_command( |
| 4 |
"SET abc bar EX 10", |
| 5 |
{ |
| 6 |
"command": "SET", |
| 7 |
"key": "abc", |
| 8 |
"value": "bar", |
| 9 |
"expiration": "EX", |
| 10 |
"millisecond": "10", |
| 11 |
}, |
| 12 |
) |
| 13 |
judge_command( |
| 14 |
"SET abc bar px 10000", |
| 15 |
{ |
| 16 |
"command": "SET", |
| 17 |
"key": "abc", |
| 18 |
"value": "bar", |
| 19 |
"expiration": "px", |
| 20 |
"millisecond": "10000", |
| 21 |
}, |
| 22 |
) |
| 23 |
judge_command( |
| 24 |
"SET abc bar px 10000 nx", |
| 25 |
{ |
| 26 |
"command": "SET", |
| 27 |
"key": "abc", |
| 28 |
"value": "bar", |
| 29 |
"expiration": "px", |
| 30 |
"millisecond": "10000", |
| 31 |
"condition": "nx", |
| 32 |
}, |
| 33 |
) |
| 34 |
judge_command( |
| 35 |
"SET abc bar px 10000 XX", |
| 36 |
{ |
| 37 |
"command": "SET", |
| 38 |
"key": "abc", |
| 39 |
"value": "bar", |
| 40 |
"expiration": "px", |
| 41 |
"millisecond": "10000", |
| 42 |
"condition": "XX", |
| 43 |
}, |
| 44 |
) |
| 45 |
judge_command( |
| 46 |
"SET abc bar XX px 10000", |
| 47 |
{ |
| 48 |
"command": "SET", |
| 49 |
"key": "abc", |
| 50 |
"value": "bar", |
| 51 |
"expiration": "px", |
| 52 |
"millisecond": "10000", |
| 53 |
"condition": "XX", |
| 54 |
}, |
| 55 |
) |
| 56 |
judge_command( |
| 57 |
"SET abc bar XX", |
| 58 |
{"command": "SET", "key": "abc", "value": "bar", "condition": "XX"}, |
| 59 |
) |
| 60 |
# keepttl |
| 61 |
judge_command( |
| 62 |
"SET abc bar XX keepttl", |
| 63 |
{ |
| 64 |
"command": "SET", |
| 65 |
"key": "abc", |
| 66 |
"value": "bar", |
| 67 |
"condition": "XX", |
| 68 |
"keepttl": "keepttl", |
| 69 |
}, |
| 70 |
) |
| 71 |
judge_command( |
| 72 |
"SET abc bar keepttl XX", |
| 73 |
{ |
| 74 |
"command": "SET", |
| 75 |
"key": "abc", |
| 76 |
"value": "bar", |
| 77 |
"condition": "XX", |
| 78 |
"keepttl": "keepttl", |
| 79 |
}, |
| 80 |
) |
| 81 |
judge_command( |
| 82 |
"SET abc bar XX px 10000 KEEPTTL", |
| 83 |
{ |
| 84 |
"command": "SET", |
| 85 |
"key": "abc", |
| 86 |
"value": "bar", |
| 87 |
"expiration": "px", |
| 88 |
"millisecond": "10000", |
| 89 |
"condition": "XX", |
| 90 |
"keepttl": "KEEPTTL", |
| 91 |
}, |
| 92 |
) |
| 93 |
# GET option (since 6.2.0, redis-doc) |
| 94 |
judge_command( |
| 95 |
"SET abc bar GET", |
| 96 |
{ |
| 97 |
"command": "SET", |
| 98 |
"key": "abc", |
| 99 |
"value": "bar", |
| 100 |
"get": "GET", |
| 101 |
}, |
| 102 |
) |
| 103 |
# EXAT / PXAT options (since 6.2.0, redis-doc) |
| 104 |
judge_command( |
| 105 |
"SET abc bar EXAT 1234567890", |
| 106 |
{ |
| 107 |
"command": "SET", |
| 108 |
"key": "abc", |
| 109 |
"value": "bar", |
| 110 |
"exat_const": "EXAT", |
| 111 |
"timestamp": "1234567890", |
| 112 |
}, |
| 113 |
) |
| 114 |
judge_command( |
| 115 |
"SET abc bar PXAT 1234567890123", |
| 116 |
{ |
| 117 |
"command": "SET", |
| 118 |
"key": "abc", |
| 119 |
"value": "bar", |
| 120 |
"pxat_const": "PXAT", |
| 121 |
"timestampms": "1234567890123", |
| 122 |
}, |
| 123 |
) |
| 124 |
|
| 125 |
|
| 126 |
def test_append(judge_command): |
| 127 |
judge_command("append foo bar", {"command": "append", "key": "foo", "value": "bar"}) |
| 128 |
judge_command( |
| 129 |
"APPEND foo 'bar'", {"command": "APPEND", "key": "foo", "value": "'bar'"} |
| 130 |
) |
| 131 |
judge_command("APPEND foo", None) |
| 132 |
|
| 133 |
|
| 134 |
def test_bitcount(judge_command): |
| 135 |
judge_command("bitcount foo", {"command": "bitcount", "key": "foo"}) |
| 136 |
judge_command( |
| 137 |
"bitcount foo 1 5", |
| 138 |
{"command": "bitcount", "key": "foo", "start": "1", "end": "5"}, |
| 139 |
) |
| 140 |
judge_command( |
| 141 |
"bitcount foo 1 -5", |
| 142 |
{"command": "bitcount", "key": "foo", "start": "1", "end": "-5"}, |
| 143 |
) |
| 144 |
judge_command( |
| 145 |
"bitcount foo -2 -1", |
| 146 |
{"command": "bitcount", "key": "foo", "start": "-2", "end": "-1"}, |
| 147 |
) |
| 148 |
judge_command("bitcount foo -2", None) |
| 149 |
|
| 150 |
|
| 151 |
def test_getrange(judge_command): |
| 152 |
judge_command("getrange foo", None) |
| 153 |
judge_command( |
| 154 |
"getrange foo 1 5", |
| 155 |
{"command": "getrange", "key": "foo", "start": "1", "end": "5"}, |
| 156 |
) |
| 157 |
judge_command( |
| 158 |
"getrange foo 1 -5", |
| 159 |
{"command": "getrange", "key": "foo", "start": "1", "end": "-5"}, |
| 160 |
) |
| 161 |
judge_command( |
| 162 |
"getrange foo -2 -1", |
| 163 |
{"command": "getrange", "key": "foo", "start": "-2", "end": "-1"}, |
| 164 |
) |
| 165 |
judge_command("getrange foo -2", None) |
| 166 |
|
| 167 |
|
| 168 |
def test_get_set(judge_command): |
| 169 |
judge_command("GETSET abc bar", {"command": "GETSET", "key": "abc", "value": "bar"}) |
| 170 |
|
| 171 |
|
| 172 |
def test_incr(judge_command): |
| 173 |
judge_command("INCR foo", {"command": "INCR", "key": "foo"}) |
| 174 |
judge_command("INCR", None) |
| 175 |
judge_command("INCR foo 1", None) |
| 176 |
|
| 177 |
|
| 178 |
def test_incr_by(judge_command): |
| 179 |
judge_command("INCRBY foo", None) |
| 180 |
judge_command("INCRBY", None) |
| 181 |
judge_command("INCRBY foo 1", {"command": "INCRBY", "key": "foo", "delta": "1"}) |
| 182 |
judge_command("INCRBY foo 200", {"command": "INCRBY", "key": "foo", "delta": "200"}) |
| 183 |
judge_command("INCRBY foo -21", {"command": "INCRBY", "key": "foo", "delta": "-21"}) |
| 184 |
|
| 185 |
|
| 186 |
def test_decr(judge_command): |
| 187 |
judge_command("DECR foo", {"command": "DECR", "key": "foo"}) |
| 188 |
judge_command("DECR", None) |
| 189 |
judge_command("DECR foo 1", None) |
| 190 |
|
| 191 |
|
| 192 |
def test_decr_by(judge_command): |
| 193 |
judge_command("DECRBY foo", None) |
| 194 |
judge_command("DECRBY", None) |
| 195 |
judge_command("DECRBY foo 1", {"command": "DECRBY", "key": "foo", "delta": "1"}) |
| 196 |
judge_command("DECRBY foo 200", {"command": "DECRBY", "key": "foo", "delta": "200"}) |
| 197 |
judge_command("DECRBY foo -21", {"command": "DECRBY", "key": "foo", "delta": "-21"}) |
| 198 |
|
| 199 |
|
| 200 |
def test_command_set_range(judge_command): |
| 201 |
judge_command( |
| 202 |
"SETRANGE foo 10 bar", |
| 203 |
{"command": "SETRANGE", "key": "foo", "offset": "10", "value": "bar"}, |
| 204 |
) |
| 205 |
judge_command("SETRANGE foo bar", None) |
| 206 |
judge_command( |
| 207 |
"SETRANGE Redis 10 'hello world'", |
| 208 |
{ |
| 209 |
"command": "SETRANGE", |
| 210 |
"key": "Redis", |
| 211 |
"offset": "10", |
| 212 |
"value": "'hello world'", |
| 213 |
}, |
| 214 |
) |
| 215 |
|
| 216 |
|
| 217 |
def test_command_set_ex(judge_command): |
| 218 |
judge_command( |
| 219 |
"SETEX key 10 value", |
| 220 |
{"command": "SETEX", "key": "key", "second": "10", "value": "value"}, |
| 221 |
) |
| 222 |
judge_command("SETEX foo 10", None) |
| 223 |
judge_command( |
| 224 |
"setex Redis 10 'hello world'", |
| 225 |
{"command": "setex", "key": "Redis", "second": "10", "value": "'hello world'"}, |
| 226 |
) |
| 227 |
|
| 228 |
|
| 229 |
def test_command_setbit(judge_command): |
| 230 |
judge_command( |
| 231 |
"SETBIT key 10 0", |
| 232 |
{"command": "SETBIT", "key": "key", "offset": "10", "bit": "0"}, |
| 233 |
) |
| 234 |
judge_command( |
| 235 |
"SETBIT foo 10 1", |
| 236 |
{"command": "SETBIT", "key": "foo", "offset": "10", "bit": "1"}, |
| 237 |
) |
| 238 |
judge_command("SETBIT foo 10 10", None) |
| 239 |
judge_command("SETBIT foo 10 abc", None) |
| 240 |
judge_command("SETBIT foo 10", None) |
| 241 |
judge_command("SETBIT foo", None) |
| 242 |
|
| 243 |
|
| 244 |
def test_command_getbit(judge_command): |
| 245 |
judge_command("GETBIT key 10", {"command": "GETBIT", "key": "key", "offset": "10"}) |
| 246 |
judge_command("GETBIT foo 0", {"command": "GETBIT", "key": "foo", "offset": "0"}) |
| 247 |
judge_command("GETBIT foo -1", None) |
| 248 |
judge_command("SETBIT foo abc", None) |
| 249 |
judge_command("SETBIT foo", None) |
| 250 |
|
| 251 |
|
| 252 |
def test_command_incrbyfloat(judge_command): |
| 253 |
judge_command("INCRBYFLOAT key", None) |
| 254 |
judge_command( |
| 255 |
"INCRBYFLOAT key 1.1", {"command": "INCRBYFLOAT", "key": "key", "float": "1.1"} |
| 256 |
) |
| 257 |
judge_command( |
| 258 |
"INCRBYFLOAT key .1", {"command": "INCRBYFLOAT", "key": "key", "float": ".1"} |
| 259 |
) |
| 260 |
judge_command( |
| 261 |
"INCRBYFLOAT key 1.", {"command": "INCRBYFLOAT", "key": "key", "float": "1."} |
| 262 |
) |
| 263 |
judge_command( |
| 264 |
"INCRBYFLOAT key 5.0e3", |
| 265 |
{"command": "INCRBYFLOAT", "key": "key", "float": "5.0e3"}, |
| 266 |
) |
| 267 |
judge_command( |
| 268 |
"INCRBYFLOAT key -5.0e3", |
| 269 |
{"command": "INCRBYFLOAT", "key": "key", "float": "-5.0e3"}, |
| 270 |
) |
| 271 |
|
| 272 |
|
| 273 |
def test_command_mget(judge_command): |
| 274 |
judge_command("mget foo bar", {"command": "mget", "keys": "foo bar"}) |
| 275 |
|
| 276 |
|
| 277 |
def test_mset(judge_command): |
| 278 |
judge_command("mset foo bar", {"command": "mset", "key": "foo", "value": "bar"}) |
| 279 |
judge_command( |
| 280 |
"mset foo bar hello world", |
| 281 |
{"command": "mset", "key": "hello", "value": "world"}, |
| 282 |
) |
| 283 |
|
| 284 |
|
| 285 |
def test_psetex(judge_command): |
| 286 |
judge_command( |
| 287 |
"psetex foo 1000 bar", |
| 288 |
{"command": "psetex", "key": "foo", "value": "bar", "millisecond": "1000"}, |
| 289 |
) |
| 290 |
judge_command("psetex foo bar", None) |
| 291 |
|
| 292 |
|
| 293 |
def test_bitop(judge_command): |
| 294 |
judge_command( |
| 295 |
"BITOP AND dest key1 key2", |
| 296 |
{"command": "BITOP", "operation": "AND", "key": "dest", "keys": "key1 key2"}, |
| 297 |
) |
| 298 |
judge_command( |
| 299 |
"BITOP AND dest key1", |
| 300 |
{"command": "BITOP", "operation": "AND", "key": "dest", "keys": "key1"}, |
| 301 |
) |
| 302 |
judge_command("BITOP AND dest", None) |
| 303 |
|
| 304 |
|
| 305 |
def test_bitpos(judge_command): |
| 306 |
judge_command( |
| 307 |
"BITPOS mykey 1 3 5", |
| 308 |
{"command": "BITPOS", "key": "mykey", "bit": "1", "start": "3", "end": "5"}, |
| 309 |
) |
| 310 |
judge_command("BITPOS mykey 1", {"command": "BITPOS", "key": "mykey", "bit": "1"}) |
| 311 |
judge_command( |
| 312 |
"BITPOS mykey 1 3", |
| 313 |
{"command": "BITPOS", "key": "mykey", "bit": "1", "start": "3"}, |
| 314 |
) |
| 315 |
|
| 316 |
|
| 317 |
def test_bitfield(judge_command): |
| 318 |
judge_command( |
| 319 |
"BITFIELD mykey INCRBY i5 100 1 GET u4 0", |
| 320 |
{ |
| 321 |
"command": "BITFIELD", |
| 322 |
"key": "mykey", |
| 323 |
"incrby": "INCRBY", |
| 324 |
"inttype": ["i5", "u4"], |
| 325 |
"offset": ["100", "0"], |
| 326 |
"value": "1", |
| 327 |
"get": "GET", |
| 328 |
}, |
| 329 |
) |
| 330 |
judge_command( |
| 331 |
"BITFIELD mystring SET i8 #0 100", |
| 332 |
{ |
| 333 |
"command": "BITFIELD", |
| 334 |
"key": "mystring", |
| 335 |
"set": "SET", |
| 336 |
"inttype": "i8", |
| 337 |
"offset": "#0", |
| 338 |
"value": "100", |
| 339 |
}, |
| 340 |
) |
| 341 |
judge_command( |
| 342 |
"BITFIELD mykey incrby u2 100 1 OVERFLOW SAT incrby u2 102 1", |
| 343 |
{ |
| 344 |
"command": "BITFIELD", |
| 345 |
"key": "mykey", |
| 346 |
"incrby": "incrby", |
| 347 |
"inttype": "u2", |
| 348 |
"offset": "102", |
| 349 |
"value": "1", |
| 350 |
"overflow": "OVERFLOW", |
| 351 |
"overflow_option": "SAT", |
| 352 |
}, |
| 353 |
) |
| 354 |
|
| 355 |
|
| 356 |
def test_stralgo(judge_command): |
| 357 |
judge_command( |
| 358 |
"STRALGO LCS STRINGS ohmytext mynewtext", |
| 359 |
{ |
| 360 |
"command": "STRALGO", |
| 361 |
"str_algo": "LCS", |
| 362 |
"strings_const": "STRINGS", |
| 363 |
"values": "ohmytext mynewtext", |
| 364 |
}, |
| 365 |
) |
| 366 |
|
| 367 |
# Due to redis' command design, this can't be fix in any ways. |
| 368 |
judge_command( |
| 369 |
"STRALGO LCS STRINGS ohmytext mynewtext LEN", |
| 370 |
{ |
| 371 |
"command": "STRALGO", |
| 372 |
"str_algo": "LCS", |
| 373 |
"strings_const": "STRINGS", |
| 374 |
"values": "ohmytext mynewtext LEN", |
| 375 |
}, |
| 376 |
) |