Class: Fabes::ConnectionAdapters::RedisAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/fabes/connection_adapters/redis_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(redis) ⇒ RedisAdapter

Returns a new instance of RedisAdapter.



12
13
14
# File 'lib/fabes/connection_adapters/redis_adapter.rb', line 12

def initialize(redis)
  @redis = redis
end

Instance Method Details

#all_experimentsObject



47
48
49
50
51
52
53
54
# File 'lib/fabes/connection_adapters/redis_adapter.rb', line 47

def all_experiments
  experiments = Array.new
  names = get_all_experiment_names
  names.each do |name|
    experiments << load_experiment(name)
  end
  experiments
end

#clear!Object



16
17
18
# File 'lib/fabes/connection_adapters/redis_adapter.rb', line 16

def clear!
  @redis.flushdb
end

#find_experiment(name) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/fabes/connection_adapters/redis_adapter.rb', line 27

def find_experiment(name)
  if @redis.sismember "fabes:experiments", name
    load_experiment(name)
  else
    nil
  end
end

#increment_hits!(id) ⇒ Object



35
36
37
# File 'lib/fabes/connection_adapters/redis_adapter.rb', line 35

def increment_hits!(id)
  @redis.hincrby "fabes:alternatives_pool:#{id}", 'hits', 1
end

#increment_participants!(id) ⇒ Object



39
40
41
# File 'lib/fabes/connection_adapters/redis_adapter.rb', line 39

def increment_participants!(id)
  @redis.hincrby "fabes:alternatives_pool:#{id}", 'participants', 1
end

#save_experiment(experiment) ⇒ Object



20
21
22
23
24
25
# File 'lib/fabes/connection_adapters/redis_adapter.rb', line 20

def save_experiment(experiment)
  add_to_current_experiments(experiment.name)
  save_experiment_data(experiment)
rescue
  raise "Unable to save experiment"
end

#update_weight(id, weight) ⇒ Object



43
44
45
# File 'lib/fabes/connection_adapters/redis_adapter.rb', line 43

def update_weight(id, weight)
  @redis.hset "fabes:alternatives_pool:#{id}", 'weight', weight
end