Test coverage for incr/decr operation on robj encoding type optimization (#12435)

Additional test coverage for incr/decr operation.

integer number could be present in raw encoding format due to operation like append. A incr/decr operation following it optimize the string to int encoding format.
This commit is contained in:
Harkrishn Patro 2023-07-25 16:43:31 -07:00 committed by GitHub
parent 01eb939a06
commit 42985b00ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -182,4 +182,33 @@ start_server {tags {"incr"}} {
r incrbyfloat foo [expr double(-1)/41]
r get foo
} {0}
foreach cmd {"incr" "decr" "incrby" "decrby"} {
test "$cmd operation should update encoding from raw to int" {
set res {}
set expected {1 12}
if {[string match {*incr*} $cmd]} {
lappend expected 13
} else {
lappend expected 11
}
r set foo 1
assert_encoding "int" foo
lappend res [r get foo]
r append foo 2
assert_encoding "raw" foo
lappend res [r get foo]
if {[string match {*by*} $cmd]} {
r $cmd foo 1
} else {
r $cmd foo
}
assert_encoding "int" foo
lappend res [r get foo]
assert_equal $res $expected
}
}
}