diff --git a/local_examples/cmds_generic/node-redis/cmds-generic.js b/local_examples/cmds_generic/node-redis/cmds-generic.js index a3ce115f6e..7d98af31eb 100644 --- a/local_examples/cmds_generic/node-redis/cmds-generic.js +++ b/local_examples/cmds_generic/node-redis/cmds-generic.js @@ -236,17 +236,17 @@ await client.del(['geokey', 'zkey']); const scan4Res1 = await client.hSet('myhash', { a: 1, b: 2 }); console.log(scan4Res1); // 2 +// HSCAN doesn't promise a field order, so pair entries into an object rather than +// relying on position. const scan4Res2 = await client.hScan('myhash', '0'); -console.log(scan4Res2.entries); // [{field: 'a', value: '1'}, {field: 'b', value: '2'}] +const scan4Pairs = Object.fromEntries(scan4Res2.entries.map((e) => [e.field, e.value])); +console.log(scan4Pairs); // {a: '1', b: '2'} // REMOVE_START -assert.deepEqual(scan4Res2.entries, [ - { field: 'a', value: '1' }, - { field: 'b', value: '2' } -]); +assert.deepEqual(scan4Pairs, { a: '1', b: '2' }); // REMOVE_END const scan4Res3 = await client.hScan('myhash', '0', { COUNT: 10 }); -const items = scan4Res3.entries.map((item) => item.field) +const items = scan4Res3.entries.map((item) => item.field).sort() console.log(items); // ['a', 'b'] // REMOVE_START assert.deepEqual(items, ['a', 'b']) diff --git a/local_examples/cmds_generic/redis-py/cmds_generic.py b/local_examples/cmds_generic/redis-py/cmds_generic.py index 2e48e62366..e0470d49df 100644 --- a/local_examples/cmds_generic/redis-py/cmds_generic.py +++ b/local_examples/cmds_generic/redis-py/cmds_generic.py @@ -261,10 +261,10 @@ # REMOVE_END cursor, keys = r.hscan("myhash", 0, no_values=True) -print(keys) +print(sorted(keys)) # >>> ['a', 'b'] # REMOVE_START -assert keys == ['a', 'b'] +assert sorted(keys) == ['a', 'b'] # REMOVE_END # REMOVE_START diff --git a/local_examples/cmds_hash/node-redis/cmds-hash.js b/local_examples/cmds_hash/node-redis/cmds-hash.js index 26992a33b2..55bfa1d263 100644 --- a/local_examples/cmds_hash/node-redis/cmds-hash.js +++ b/local_examples/cmds_hash/node-redis/cmds-hash.js @@ -129,7 +129,8 @@ const res12 = await client.hSet( } ) -const res13 = await client.hVals('myhash') +// HVALS follows the hash's field order, which Redis does not promise, so sort. +const res13 = (await client.hVals('myhash')).sort() console.log(res13) // [ 'Hello', 'World' ] // REMOVE_START diff --git a/local_examples/cmds_hash/predis/CmdsHashTest.php b/local_examples/cmds_hash/predis/CmdsHashTest.php index d9f110bdb3..4569d7177c 100644 --- a/local_examples/cmds_hash/predis/CmdsHashTest.php +++ b/local_examples/cmds_hash/predis/CmdsHashTest.php @@ -133,7 +133,9 @@ public function testCmdsHash(): void $hValsResult1 = $this->redis->hmset('myhash', ['field1' => 'Hello', 'field2' => 'World']); echo "HMSET myhash field1 Hello field2 World: " . ($hValsResult1 ? 'OK' : 'FAIL') . "\n"; // >>> OK + // HVALS follows the hash's field order, which Redis does not promise, so sort. $hValsResult2 = $this->redis->hvals('myhash'); + sort($hValsResult2); echo "HVALS myhash: " . json_encode($hValsResult2) . "\n"; // >>> ["Hello","World"] // STEP_END diff --git a/local_examples/cmds_hash/redis-py/cmds_hash.py b/local_examples/cmds_hash/redis-py/cmds_hash.py index 8b70077aa1..2e512857d4 100644 --- a/local_examples/cmds_hash/redis-py/cmds_hash.py +++ b/local_examples/cmds_hash/redis-py/cmds_hash.py @@ -110,11 +110,12 @@ # STEP_START hvals res10 = r.hset("myhash", mapping={"field1": "Hello", "field2": "World"}) +# HVALS follows the hash's field order, which Redis does not promise, so sort. res11 = r.hvals("myhash") -print(res11) # >>> [ "Hello", "World" ] +print(sorted(res11)) # >>> [ "Hello", "World" ] # REMOVE_START -assert res11 == [ "Hello", "World" ] +assert sorted(res11) == [ "Hello", "World" ] r.delete("myhash") # REMOVE_END # STEP_END diff --git a/local_examples/cmds_hash/ruby/cmds_hash.rb b/local_examples/cmds_hash/ruby/cmds_hash.rb index dede870a2d..a8af54f255 100644 --- a/local_examples/cmds_hash/ruby/cmds_hash.rb +++ b/local_examples/cmds_hash/ruby/cmds_hash.rb @@ -107,7 +107,8 @@ def assert_equal(expected, actual) # STEP_START hvals r.hset('myhash', { 'field1' => 'Hello', 'field2' => 'World' }) -res15 = r.hvals('myhash') +# HVALS follows the hash's field order, which Redis does not promise, so sort. +res15 = r.hvals('myhash').sort puts res15.inspect # >>> ["Hello", "World"] # STEP_END diff --git a/local_examples/ruby/dt_hash.rb b/local_examples/ruby/dt_hash.rb index 494ba8554b..b6dd614224 100644 --- a/local_examples/ruby/dt_hash.rb +++ b/local_examples/ruby/dt_hash.rb @@ -30,7 +30,7 @@ def assert_equal(expected, actual) res4 = r.hgetall('bike:1') puts res4.inspect -# >>> {"model"=>"Deimos", "brand"=>"Ergonom", "type"=>"Enduro bikes", "price"=>"4972"} +# >>> {"model" => "Deimos", "brand" => "Ergonom", "type" => "Enduro bikes", "price" => "4972"} # STEP_END # REMOVE_START diff --git a/local_examples/ruby/dt_stream.rb b/local_examples/ruby/dt_stream.rb index f8e8166f09..e43e7a5729 100644 --- a/local_examples/ruby/dt_stream.rb +++ b/local_examples/ruby/dt_stream.rb @@ -70,8 +70,8 @@ # HIDE_END res4 = r.xrange('race:france', '1692632086370-0', '+', count: 2) puts res4.inspect -# >>> [["1692632086370-0", {"rider"=>"Castilla", "speed"=>"30.2", "position"=>"1", "location_id"=>"1"}], -# ["1692632094485-0", {"rider"=>"Norem", "speed"=>"28.8", "position"=>"3", "location_id"=>"1"}]] +# >>> [["1692632086370-0", {"rider" => "Castilla", "speed" => "30.2", "position" => "1", "location_id" => "1"}], +# ["1692632094485-0", {"rider" => "Norem", "speed" => "28.8", "position" => "3", "location_id" => "1"}]] # STEP_END # REMOVE_START @@ -181,10 +181,10 @@ # HIDE_END res11 = r.xrange('race:france', '-', '+') puts res11.inspect -# >>> [["1692632086370-0", {"rider"=>"Castilla", "speed"=>"30.2", "position"=>"1", "location_id"=>"1"}], -# ["1692632094485-0", {"rider"=>"Norem", "speed"=>"28.8", "position"=>"3", "location_id"=>"1"}], -# ["1692632102976-0", {"rider"=>"Prickett", "speed"=>"29.7", "position"=>"2", "location_id"=>"1"}], -# ["1692632147973-0", {"rider"=>"Castilla", "speed"=>"29.9", "position"=>"1", "location_id"=>"2"}]] +# >>> [["1692632086370-0", {"rider" => "Castilla", "speed" => "30.2", "position" => "1", "location_id" => "1"}], +# ["1692632094485-0", {"rider" => "Norem", "speed" => "28.8", "position" => "3", "location_id" => "1"}], +# ["1692632102976-0", {"rider" => "Prickett", "speed" => "29.7", "position" => "2", "location_id" => "1"}], +# ["1692632147973-0", {"rider" => "Castilla", "speed" => "29.9", "position" => "1", "location_id" => "2"}]] # STEP_END # REMOVE_START @@ -199,7 +199,7 @@ # HIDE_END res12 = r.xrange('race:france', '1692632086369', '1692632086371') puts res12.inspect -# >>> [["1692632086370-0", {"rider"=>"Castilla", "speed"=>"30.2", "position"=>"1", "location_id"=>"1"}]] +# >>> [["1692632086370-0", {"rider" => "Castilla", "speed" => "30.2", "position" => "1", "location_id" => "1"}]] # STEP_END # REMOVE_START @@ -217,8 +217,8 @@ # HIDE_END res13 = r.xrange('race:france', '-', '+', count: 2) puts res13.inspect -# >>> [["1692632086370-0", {"rider"=>"Castilla", "speed"=>"30.2", "position"=>"1", "location_id"=>"1"}], -# ["1692632094485-0", {"rider"=>"Norem", "speed"=>"28.8", "position"=>"3", "location_id"=>"1"}]] +# >>> [["1692632086370-0", {"rider" => "Castilla", "speed" => "30.2", "position" => "1", "location_id" => "1"}], +# ["1692632094485-0", {"rider" => "Norem", "speed" => "28.8", "position" => "3", "location_id" => "1"}]] # STEP_END # REMOVE_START @@ -235,8 +235,8 @@ # HIDE_END res14 = r.xrange('race:france', '(1692632094485-0', '+', count: 2) puts res14.inspect -# >>> [["1692632102976-0", {"rider"=>"Prickett", "speed"=>"29.7", "position"=>"2", "location_id"=>"1"}], -# ["1692632147973-0", {"rider"=>"Castilla", "speed"=>"29.9", "position"=>"1", "location_id"=>"2"}]] +# >>> [["1692632102976-0", {"rider" => "Prickett", "speed" => "29.7", "position" => "2", "location_id" => "1"}], +# ["1692632147973-0", {"rider" => "Castilla", "speed" => "29.9", "position" => "1", "location_id" => "2"}]] # STEP_END # REMOVE_START @@ -255,7 +255,7 @@ # STEP_START xrevrange res16 = r.xrevrange('race:france', '+', '-', count: 1) puts res16.inspect -# >>> [["1692632147973-0", {"rider"=>"Castilla", "speed"=>"29.9", "position"=>"1", "location_id"=>"2"}]] +# >>> [["1692632147973-0", {"rider" => "Castilla", "speed" => "29.9", "position" => "1", "location_id" => "2"}]] # STEP_END # REMOVE_START @@ -265,8 +265,8 @@ # STEP_START xread res17 = r.xread(['race:france'], ['0'], count: 2) puts res17.inspect -# >>> {"race:france"=>[["1692632086370-0", {"rider"=>"Castilla", "speed"=>"30.2", "position"=>"1", "location_id"=>"1"}], -# ["1692632094485-0", {"rider"=>"Norem", "speed"=>"28.8", "position"=>"3", "location_id"=>"1"}]]} +# >>> {"race:france"=>[["1692632086370-0", {"rider" => "Castilla", "speed" => "30.2", "position" => "1", "location_id" => "1"}], +# ["1692632094485-0", {"rider" => "Norem", "speed" => "28.8", "position" => "3", "location_id" => "1"}]]} # STEP_END # REMOVE_START @@ -311,7 +311,7 @@ res20 = r.xreadgroup('italy_riders', 'Alice', ['race:italy'], ['>'], count: 1) puts res20.inspect -# >>> {"race:italy"=>[["1692632639151-0", {"rider"=>"Castilla"}]]} +# >>> {"race:italy"=>[["1692632639151-0", {"rider" => "Castilla"}]]} # STEP_END # REMOVE_START @@ -321,7 +321,7 @@ # STEP_START xgroup_read_id res21 = r.xreadgroup('italy_riders', 'Alice', ['race:italy'], ['0'], count: 1) puts res21.inspect -# >>> {"race:italy"=>[["1692632639151-0", {"rider"=>"Castilla"}]]} +# >>> {"race:italy"=>[["1692632639151-0", {"rider" => "Castilla"}]]} # STEP_END # REMOVE_START @@ -345,8 +345,8 @@ # STEP_START xgroup_read_bob res24 = r.xreadgroup('italy_riders', 'Bob', ['race:italy'], ['>'], count: 2) puts res24.inspect -# >>> {"race:italy"=>[["1692632647899-0", {"rider"=>"Royce"}], -# ["1692632662819-0", {"rider"=>"Sam-Bodden"}]]} +# >>> {"race:italy"=>[["1692632647899-0", {"rider" => "Royce"}], +# ["1692632662819-0", {"rider" => "Sam-Bodden"}]]} # STEP_END # REMOVE_START @@ -356,7 +356,7 @@ # STEP_START xpending res25 = r.xpending('race:italy', 'italy_riders') puts res25.inspect -# >>> {"size"=>2, "min_entry_id"=>"1692632647899-0", "max_entry_id"=>"1692632662819-0", "consumers"=>{"Bob"=>"2"}} +# >>> {"size"=>2, "min_entry_id" => "1692632647899-0", "max_entry_id" => "1692632662819-0", "consumers"=>{"Bob" => "2"}} # STEP_END # REMOVE_START @@ -377,7 +377,7 @@ # STEP_START xrange_pending res27 = r.xrange('race:italy', '1692632647899-0', '1692632647899-0') puts res27.inspect -# >>> [["1692632647899-0", {"rider"=>"Royce"}]] +# >>> [["1692632647899-0", {"rider" => "Royce"}]] # STEP_END # REMOVE_START @@ -387,7 +387,7 @@ # STEP_START xclaim res28 = r.xclaim('race:italy', 'italy_riders', 'Alice', 0, '1692632647899-0') puts res28.inspect -# >>> [["1692632647899-0", {"rider"=>"Royce"}]] +# >>> [["1692632647899-0", {"rider" => "Royce"}]] # STEP_END # REMOVE_START @@ -397,7 +397,7 @@ # STEP_START xautoclaim res29 = r.xautoclaim('race:italy', 'italy_riders', 'Alice', 0, '0-0', count: 1) puts res29.inspect -# >>> {"next"=>"1692632662819-0", "entries"=>[["1692632647899-0", {"rider"=>"Royce"}]]} +# >>> {"next" => "1692632662819-0", "entries"=>[["1692632647899-0", {"rider" => "Royce"}]]} # STEP_END # REMOVE_START @@ -407,7 +407,7 @@ # STEP_START xautoclaim_cursor res30 = r.xautoclaim('race:italy', 'italy_riders', 'Lora', 0, res29['next'], count: 1) puts res30.inspect -# >>> {"next"=>"0-0", "entries"=>[["1692632662819-0", {"rider"=>"Sam-Bodden"}]]} +# >>> {"next" => "0-0", "entries"=>[["1692632662819-0", {"rider" => "Sam-Bodden"}]]} # STEP_END # REMOVE_START @@ -462,7 +462,7 @@ res35 = r.xrange('race:italy', '-', '+') puts res35.inspect -# >>> [["1692633198206-0", {"rider"=>"Wood"}], ["1692633208557-0", {"rider"=>"Henshaw"}]] +# >>> [["1692633198206-0", {"rider" => "Wood"}], ["1692633208557-0", {"rider" => "Henshaw"}]] # STEP_END # REMOVE_START @@ -502,14 +502,14 @@ # HIDE_END res38 = r.xrange('race:italy', '-', '+', count: 2) puts res38.inspect -# >>> [["1692633198206-0", {"rider"=>"Wood"}], ["1692633208557-0", {"rider"=>"Henshaw"}]] +# >>> [["1692633198206-0", {"rider" => "Wood"}], ["1692633208557-0", {"rider" => "Henshaw"}]] res39 = r.xdel('race:italy', '1692633208557-0') puts res39 # >>> 1 res40 = r.xrange('race:italy', '-', '+', count: 2) puts res40.inspect -# >>> [["1692633198206-0", {"rider"=>"Wood"}]] +# >>> [["1692633198206-0", {"rider" => "Wood"}]] # STEP_END # REMOVE_START