From 2fdac516a676aaeca86e6841ef45e1627f2ffd28 Mon Sep 17 00:00:00 2001 From: John Sully Date: Wed, 11 Nov 2020 03:29:38 +0000 Subject: [PATCH] Add missing file Former-commit-id: 97fd73692363e05b80e0c0e84b7b2b8fe7f760b8 --- tests/unit/type/nestedhash.tcl | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/unit/type/nestedhash.tcl diff --git a/tests/unit/type/nestedhash.tcl b/tests/unit/type/nestedhash.tcl new file mode 100644 index 000000000..5b2d0be52 --- /dev/null +++ b/tests/unit/type/nestedhash.tcl @@ -0,0 +1,51 @@ +start_server {tags {"nested_hash"}} { + test {Simple set/get} { + assert_equal [r keydb.nhset foo bar] 0 + assert_equal bar [r keydb.nhget foo] + } + + test {overwrite} { + r flushall + assert_equal [r keydb.nhset foo bar] 0 + assert_equal [r keydb.nhset foo baz] 1 + assert_equal [r keydb.nhget foo] baz + } + + test {get simple string} { + r keydb.nhset foo bar + assert_equal [r keydb.nhget json foo] {"bar"} + assert_equal [r keydb.nhget foo] "bar" + } + + test {get array} { + r keydb.nhset foo a b c d + assert_equal [r keydb.nhget json foo] {["a","b","c","d"]} + assert_equal [r keydb.nhget foo] {a b c d} + } + + test {overwrite string with object} { + r keydb.nhset a.b.c val1 + r keydb.nhset a.b val2 + r keydb.nhset a.b.c.d val3 + assert_equal [r keydb.nhget json a] {{"b" : {"c" : {"d" : "val3"}}}} + } + + test {malformed nested key} { + assert_error *syntax* {r keydb.nhset a..b val1} + } + + test {missing final selector key} { + assert_error *syntax* {r keydb.nhset a.b. val1} + } + + test {expire nested hash} { + r keydb.nhset a.b.c val1 + assert_equal [r expire a 100] 1 + assert [expr [r ttl a] > 0] + } + + test {expire subhash} { + r keydb.nhset a.b.c val1 + assert_equal [r expire a.b 100] 0 + } +}