Permalink
Browse files

redis_fetch

  • Loading branch information...
sorah committed Oct 22, 2017
1 parent 89bf01f commit ba8c5c640469f46a4caa051c615e9796052d8cdc
Showing with 15 additions and 0 deletions.
  1. +15 −0 isubata/webapp/ruby/app.rb
View
@@ -487,6 +487,21 @@ def redis_key_total_messages
"isubata:total_messages"
end
def redis_fetch(key, ttl: nil)
e = redis.get(key)
if e
MessagePack.unpack e
else
yield.tap do |r|
if ttl
redis.psetex(key, ms, r.to_msgpack)
else
redis.set(key, r.to_msgpack)
end
end
end
end
#def redis_key_unreads(user_id, channel_id)
# "isubata:unreads:#{user_id}:#{channel_id}"
#end

0 comments on commit ba8c5c6

Please sign in to comment.