Class: Rack::MiniProfiler::RedisStore

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

Constant Summary collapse

EXPIRES_IN_SECONDS =
60 * 60 * 24

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ RedisStore

Returns a new instance of RedisStore.



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

def initialize(args = nil)
  @args = args || {}
  @prefix = @args.delete(:prefix) || 'MPRedisStore'
  @redis_connection = @args.delete(:connection)
  @expires_in_seconds = @args.delete(:expires_in) || EXPIRES_IN_SECONDS
end

Instance Method Details

#diagnostics(user) ⇒ Object



37
38
39
40
41
42
# File 'lib/mini_profiler/storage/redis_store.rb', line 37

def diagnostics(user)
"Redis prefix: #{@prefix}
Redis location: #{redis.client.host}:#{redis.client.port} db: #{redis.client.db}
unviewed_ids: #{get_unviewed_ids(user)}
"
end

#get_unviewed_ids(user) ⇒ Object



33
34
35
# File 'lib/mini_profiler/storage/redis_store.rb', line 33

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

#load(id) ⇒ Object



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

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

#save(page_struct) ⇒ Object



14
15
16
# File 'lib/mini_profiler/storage/redis_store.rb', line 14

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

#set_unviewed(user, id) ⇒ Object



25
26
27
# File 'lib/mini_profiler/storage/redis_store.rb', line 25

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

#set_viewed(user, id) ⇒ Object



29
30
31
# File 'lib/mini_profiler/storage/redis_store.rb', line 29

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