Class: Basket::BackendAdapter::RedisBackend

Inherits:
Basket::BackendAdapter show all
Defined in:
lib/basket/backend_adapter/redis_backend.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRedisBackend

Returns a new instance of RedisBackend.



8
9
10
11
12
13
14
15
# File 'lib/basket/backend_adapter/redis_backend.rb', line 8

def initialize
  redis_connection = select_redis_connection

  @client = Redis::Namespace.new(
    Basket.config.namespace,
    redis: redis_connection
  )
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/basket/backend_adapter/redis_backend.rb', line 6

def client
  @client
end

Instance Method Details

#clear(queue) ⇒ Object



47
48
49
# File 'lib/basket/backend_adapter/redis_backend.rb', line 47

def clear(queue)
  @client.del(queue)
end

#dataObject



17
18
19
20
21
22
23
24
25
# File 'lib/basket/backend_adapter/redis_backend.rb', line 17

def data
  response = {}

  @client.scan_each do |queue|
    response[queue] = deserialized_queue_data(queue)
  end

  response
end

#length(queue) ⇒ Object



43
44
45
# File 'lib/basket/backend_adapter/redis_backend.rb', line 43

def length(queue)
  @client.llen(queue)
end

#push(queue, data) ⇒ Object



39
40
41
# File 'lib/basket/backend_adapter/redis_backend.rb', line 39

def push(queue, data)
  @client.lpush(queue, serialize_data(data))
end

#read(queue) ⇒ Object



51
52
53
# File 'lib/basket/backend_adapter/redis_backend.rb', line 51

def read(queue)
  deserialized_queue_data(queue)
end

#remove(queue, element_id) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/basket/backend_adapter/redis_backend.rb', line 31

def remove(queue, element_id)
  element = deserialized_queue_data(queue).find { |raw_element| raw_element["id"] == element_id }

  @client.lrem(queue, 1, element.to_json)

  element
end

#search(queue, &block) ⇒ Object



27
28
29
# File 'lib/basket/backend_adapter/redis_backend.rb', line 27

def search(queue, &block)
  deserialized_queue_data(queue).select { |raw_element| block.call(raw_element["data"]) }
end