Daiku
Daiku

Reputation: 1227

What's the timestamp format in a rails cache entry in redis?

When I look at a rails cache key in redis, it looks like this:

 get cache:pause_mything
"\x04\bo: ActiveSupport::Cache::Entry\t:\x0b@valueT:\r@version0:\x10@created_atf\x171598381810.4477415:\x10@expires_in0"

How do I interpret that "created_at" timestamp?

Upvotes: 0

Views: 644

Answers (1)

Siim Liiser
Siim Liiser

Reputation: 4368

The data is Marshalled. You can deserialize with ruby like so:

Marshal.load("\x04\bo: ActiveSupport::Cache::Entry\t:\x0b@valueT:\r@version0:\x10@created_atf\x171598381810.4477415:\x10@expires_in0")
# => #<ActiveSupport::Cache::Entry:0x000055904baf7ae0 @value=true, @version=nil, @created_at=1598381810.4477415, @expires_in=nil> 

This reveals that the actual value of your created_at field is 1598381810.4477415. This is just a unix timestamp, seconds since 01.01.1970. Turn it back into a Time using .at

Time.at(1598381810.4477415) # => 2020-08-25 18:56:50 +0000

Upvotes: 1

Related Questions