Class: Split::RedisInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/split/redis_interface.rb

Overview

Simplifies the interface to Redis.

Instance Method Summary collapse

Constructor Details

#initializeRedisInterface

Returns a new instance of RedisInterface.



6
7
8
# File 'lib/split/redis_interface.rb', line 6

def initialize
  self.redis = Split.redis
end

Instance Method Details

#add_to_set(set_name, value) ⇒ Object



23
24
25
26
27
# File 'lib/split/redis_interface.rb', line 23

def add_to_set(set_name, value)
  return redis.sadd?(set_name, value) if redis.respond_to?(:sadd?)

  redis.sadd(set_name, value)
end

#persist_list(list_name, list_values) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/split/redis_interface.rb', line 10

def persist_list(list_name, list_values)
  if list_values.length > 0
    redis.multi do |multi|
      tmp_list = "#{list_name}_tmp"
      tmp_list += redis_namespace_used? ? "{#{Split.redis.namespace}:#{list_name}}" : "{#{list_name}}"
      multi.rpush(tmp_list, list_values)
      multi.rename(tmp_list, list_name)
    end
  end

  list_values
end