Class: Appstats::InmemoryRedis

Inherits:
Object
  • Object
show all
Defined in:
lib/appstats/inmemory_redis.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ InmemoryRedis

Returns a new instance of InmemoryRedis.



4
5
6
7
# File 'lib/appstats/inmemory_redis.rb', line 4

def initialize(data = {})
  @sets = {}
  @lists = {}
end

Instance Method Details

#llen(key) ⇒ Object



21
22
23
24
# File 'lib/appstats/inmemory_redis.rb', line 21

def llen(key)
  return 0 if @lists[key].nil?
  @lists[key].size
end

#lrange(key, start, stop) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/appstats/inmemory_redis.rb', line 32

def lrange(key,start,stop)
  return [] if @lists[key].nil?
  start = 0 if start < 0
  max_stop = llen(key) - 1
  stop = max_stop if (stop == -1 || stop > max_stop)
  return [] if start > stop
  @lists[key][start..stop]
end

#multiObject



41
42
43
# File 'lib/appstats/inmemory_redis.rb', line 41

def multi
  yield
end

#rpush(key, value) ⇒ Object



26
27
28
29
30
# File 'lib/appstats/inmemory_redis.rb', line 26

def rpush(key,value)
  @lists[key] = [] if @lists[key].nil?
  @lists[key] << value
  true
end

#sadd(key, member) ⇒ Object



14
15
16
17
18
19
# File 'lib/appstats/inmemory_redis.rb', line 14

def sadd(key,member)
  @sets[key] = [] if @sets[key].nil?
  return false if @sets[key].include?(member)
  @sets[key] << member
  true
end

#scard(key) ⇒ Object



9
10
11
12
# File 'lib/appstats/inmemory_redis.rb', line 9

def scard(key)
  return 0 if @sets[key].nil?
  @sets[key].size
end