Skip to content

Instantly share code, notes, and snippets.

@benoittgt
Created April 27, 2023 11:22
Show Gist options
  • Select an option

  • Save benoittgt/92c58bcd412eba96644c219c04ba84f0 to your computer and use it in GitHub Desktop.

Select an option

Save benoittgt/92c58bcd412eba96644c219c04ba84f0 to your computer and use it in GitHub Desktop.
Check expiration date and cover range with Redis (RedisCacheStore) in Rails
p Rails.cache.delete("key2")
p Rails.cache.write("key2", "value2", expires_in: 2.hours)
p expiration_time = Rails.cache.redis.call("EXPIRETIME", "key2")
raise "No expiration time" if expiration_time == -1
raise "Key not found" if expiration_time == -2
p expirate_date_time = Time.at(expiration_time)
# Propably better way to check if expiration time is correct
p ((2.hours.from_now.utc - 2.minute)..(2.hours.from_now.utc + 2.minute)).cover?(expirate_date_time)
=begin
1
"OK"
1682601610
"2023-04-27T15:20:10.000+02:00"
true
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment