Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RedisStore
- include Singleton
- @store = Redis.new
- class << self
- def store_activity(a)
- @store.sadd("activities", {tkey => a}.to_json)
- @store.pop("activities") if @store.scard("activities") == 11
- end
- def get_activities
- vals = []
- @store.smembers("activities").map!{|x|
- x = JSON.parse(x)
- vals << (x[x.keys.first])
- }
- return vals
- end
- def get(k)
- r = @store.get(k)
- r.nil? ? [] : JSON.parse(r)
- end
- def tkey
- t = Time.now
- t.year.to_s <<
- t.month.to_s <<
- t.day.to_s <<
- t.hour.to_s <<
- t.min.to_s <<
- t.sec.to_s <<
- t.usec.to_s
- end
- end
- end
Add Comment
Please, Sign In to add comment