Guest User

Untitled

a guest
Jun 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. class RedisStore
  2. include Singleton
  3.  
  4. @store = Redis.new
  5.  
  6. class << self
  7.  
  8. def store_activity(a)
  9. @store.sadd("activities", {tkey => a}.to_json)
  10. @store.pop("activities") if @store.scard("activities") == 11
  11. end
  12.  
  13. def get_activities
  14. vals = []
  15. @store.smembers("activities").map!{|x|
  16. x = JSON.parse(x)
  17. vals << (x[x.keys.first])
  18. }
  19. return vals
  20. end
  21.  
  22. def get(k)
  23. r = @store.get(k)
  24. r.nil? ? [] : JSON.parse(r)
  25. end
  26.  
  27. def tkey
  28. t = Time.now
  29. t.year.to_s <<
  30. t.month.to_s <<
  31. t.day.to_s <<
  32. t.hour.to_s <<
  33. t.min.to_s <<
  34. t.sec.to_s <<
  35. t.usec.to_s
  36. end
  37. end
  38. end
Add Comment
Please, Sign In to add comment