【问题标题】:What's the timestamp format in a rails cache entry in redis?redis中rails缓存条目中的时间戳格式是什么?
【发布时间】:2021-01-10 00:03:58
【问题描述】:

当我在 redis 中查看 rails 缓存键时,它看起来像这样:

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

如何解释“created_at”时间戳?

【问题讨论】:

    标签: ruby-on-rails redis


    【解决方案1】:

    数据为Marshalled。您可以像这样使用 ruby​​ 反序列化:

    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> 
    

    这表明 created_at 字段的实际值为1598381810.4477415。这只是一个 unix 时间戳,自 01.01.1970 以来的秒数。使用.at 将其转回Time

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

    【讨论】:

      猜你喜欢
      • 2013-12-25
      • 2013-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      • 2013-05-16
      • 1970-01-01
      • 2021-10-29
      相关资源
      最近更新 更多