Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions content/develop/data-types/hashes.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ it runs on its own.
Set a TTL of 60 seconds for two fields of a hash and then retrieve the remaining TTL for
those fields:

{{< clients-example set="hash_tutorial" step="hexpire" lang_filter="Python, Node.js, Java-Sync, Java-Async, Java-Reactive, Go, C#-Sync (SE.Redis), PHP, Rust-Sync, Rust-Async" description="Field expiration: Set a TTL in seconds on individual hash fields using HEXPIRE, then read the remaining TTL with HTTL" difficulty="intermediate" buildsUpon="set_get_all" >}}
{{< clients-example set="hash_tutorial" step="hexpire" description="Field expiration: Set a TTL in seconds on individual hash fields using HEXPIRE, then read the remaining TTL with HTTL" difficulty="intermediate" buildsUpon="set_get_all" >}}
> DEL sensor:sensor1
(integer) 0
> HSET sensor:sensor1 air_quality 256 battery_level 89
Expand All @@ -177,7 +177,7 @@ those fields:

Set a hash field's TTL in milliseconds and then retrieve the remaining TTL in milliseconds:

{{< clients-example set="hash_tutorial" step="hpexpire" lang_filter="Python, Node.js, Java-Sync, Java-Async, Java-Reactive, Go, C#-Sync (SE.Redis), PHP, Rust-Sync, Rust-Async" description="Field expiration: Set a TTL in milliseconds on a hash field using HPEXPIRE, then read the remaining TTL with HPTTL" difficulty="intermediate" buildsUpon="set_get_all" >}}
{{< clients-example set="hash_tutorial" step="hpexpire" description="Field expiration: Set a TTL in milliseconds on a hash field using HPEXPIRE, then read the remaining TTL with HPTTL" difficulty="intermediate" buildsUpon="set_get_all" >}}
> DEL sensor:sensor1
(integer) 1
> HSET sensor:sensor1 air_quality 256 battery_level 89
Expand Down
41 changes: 40 additions & 1 deletion local_examples/ruby/dt_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def assert_equal(expected, actual)
raise "Expected #{expected.inspect}, got #{actual.inspect}" unless actual == expected
end

r.del('bike:1', 'bike:1:stats')
r.del('bike:1', 'bike:1:stats', 'sensor:sensor1')
# REMOVE_END

# STEP_START set_get_all
Expand Down Expand Up @@ -116,5 +116,44 @@ def assert_equal(expected, actual)
assert_equal(1, res12)
assert_equal('3', res13)
assert_equal(['1', '1'], res14)
# REMOVE_END

# STEP_START hexpire
r.del('sensor:sensor1')
r.hset('sensor:sensor1', { 'air_quality' => 256, 'battery_level' => 89 })

# Set a TTL of 60 seconds on two fields of the hash.
res15 = r.hexpire('sensor:sensor1', 60, 'air_quality', 'battery_level')
puts res15.inspect # >>> [1, 1]

# Retrieve the remaining TTL for those fields.
res16 = r.httl('sensor:sensor1', 'air_quality', 'battery_level')
puts res16.inspect # >>> [60, 60]
# (your actual values may be slightly lower)
# STEP_END

# REMOVE_START
assert_equal([1, 1], res15)
raise "Unexpected TTLs: #{res16.inspect}" unless res16.all? { |ttl| ttl.positive? && ttl <= 60 }
# REMOVE_END

# STEP_START hpexpire
r.del('sensor:sensor1')
r.hset('sensor:sensor1', { 'air_quality' => 256, 'battery_level' => 89 })

# Set the TTL of the 'air_quality' field in milliseconds.
res17 = r.hpexpire('sensor:sensor1', 60_000, 'air_quality')
puts res17.inspect # >>> [1]

# Retrieve the remaining TTL in milliseconds.
res18 = r.hpttl('sensor:sensor1', 'air_quality')
puts res18.inspect # >>> [59999]
# (your actual value may vary)
# STEP_END

# REMOVE_START
assert_equal([1], res17)
raise "Unexpected TTL: #{res18.inspect}" unless res18.all? { |pttl| pttl.positive? && pttl <= 60_000 }
r.del('bike:1', 'bike:1:stats', 'sensor:sensor1')
r.close
# REMOVE_END
Loading