Class: Rack::MiniProfiler::RedisStore

Inherits:
AbstractStore show all
Defined in:
lib/mini_profiler/storage/redis_store.rb

Constant Summary collapse

EXPIRE_SECONDS =
60 * 60 * 24

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ RedisStore

Returns a new instance of RedisStore.



7
8
9
10
# File 'lib/mini_profiler/storage/redis_store.rb', line 7

def initialize(args)
  args ||= {}
  @prefix = args[:prefix] || 'MPRedisStore'
end

Instance Method Details

#get_unviewed_ids(user) ⇒ Object



31
32
33
# File 'lib/mini_profiler/storage/redis_store.rb', line 31

def get_unviewed_ids(user)
  redis.smembers "#{@prefix}-#{user}-v"
end

#load(id) ⇒ Object



16
17
18
19
20
21
# File 'lib/mini_profiler/storage/redis_store.rb', line 16

def load(id)
  raw = redis.get "#{@prefix}#{id}"
  if raw
    Marshal::load raw
  end
end

#save(page_struct) ⇒ Object



12
13
14
# File 'lib/mini_profiler/storage/redis_store.rb', line 12

def save(page_struct)
  redis.setex "#{@prefix}#{page_struct['Id']}", EXPIRE_SECONDS, Marshal::dump(page_struct) 
end

#set_unviewed(user, id) ⇒ Object



23
24
25
# File 'lib/mini_profiler/storage/redis_store.rb', line 23

def set_unviewed(user, id)
  redis.sadd "#{@prefix}-#{user}-v", id
end

#set_viewed(user, id) ⇒ Object



27
28
29
# File 'lib/mini_profiler/storage/redis_store.rb', line 27

def set_viewed(user, id)
  redis.srem "#{@prefix}-#{user}-v", id
end