Module: Scales::Storage::Async

Defined in:
lib/scales-core/storage/async.rb

Constant Summary collapse

@@redis =
nil
@@pids =
[Process.pid]

Class Method Summary collapse

Class Method Details

.add(queue, job) ⇒ Object



46
47
48
# File 'lib/scales-core/storage/async.rb', line 46

def add(queue, job)
  with_connection{ @@redis.lpush(queue, job) }
end

.connect!Object



9
10
11
12
# File 'lib/scales-core/storage/async.rb', line 9

def connect!
  return if @@redis and @@redis.connected?
  @@redis = new_connection!
end

.connectionObject



18
19
20
# File 'lib/scales-core/storage/async.rb', line 18

def connection
  with_connection{ @@redis }
end

.del(key) ⇒ Object



42
43
44
# File 'lib/scales-core/storage/async.rb', line 42

def del(key)
  with_connection{ @@redis.del(key) }
end

.del_content(path) ⇒ Object



30
31
32
# File 'lib/scales-core/storage/async.rb', line 30

def del_content(path)
  del(Storage.prefix(path))
end

.flushall!Object



62
63
64
# File 'lib/scales-core/storage/async.rb', line 62

def flushall!
  with_connection{ @@redis.flushall }
end

.force_reconnect!Object



14
15
16
# File 'lib/scales-core/storage/async.rb', line 14

def force_reconnect!
  @@redis = new_connection!
end

.get(key, partials = false) ⇒ Object



38
39
40
# File 'lib/scales-core/storage/async.rb', line 38

def get(key, partials = false)
  with_connection{ partials ? Helper::PartialResolver.resolve(@@redis, key) : @@redis.get(key) }
end

.get_content(path, partials = false) ⇒ Object



26
27
28
# File 'lib/scales-core/storage/async.rb', line 26

def get_content(path, partials = false)
  get(Storage.prefix(path), partials)
end

.new_connection!Object



66
67
68
# File 'lib/scales-core/storage/async.rb', line 66

def new_connection!
  EM::Hiredis.connect "redis://:#{Scales.config.password}@#{Scales.config.host}:#{Scales.config.port}/#{Scales.config.database}"
end

.pop(queue) ⇒ Object



50
51
52
# File 'lib/scales-core/storage/async.rb', line 50

def pop(queue)
  with_new_connection{ |redis| redis.brpop(queue, 0) }.last
end

.publish(channel, message) ⇒ Object



54
55
56
# File 'lib/scales-core/storage/async.rb', line 54

def publish(channel, message)
  add(channel, message)
end

.set(key, value) ⇒ Object



34
35
36
# File 'lib/scales-core/storage/async.rb', line 34

def set(key, value)
  with_connection{ @@redis.set(key, value) }
end

.set_content(path, value) ⇒ Object



22
23
24
# File 'lib/scales-core/storage/async.rb', line 22

def set_content(path, value)
  set(Storage.prefix(path), value)
end

.subscribe(channel) ⇒ Object



58
59
60
# File 'lib/scales-core/storage/async.rb', line 58

def subscribe(channel)
  pop(channel)
end