Module: Slanger::Redis

Extended by:
Forwardable, Redis
Included in:
Redis
Defined in:
lib/slanger/redis.rb

Instance Method Summary collapse

Instance Method Details

#hdel(*arg) ⇒ Object



33
34
35
# File 'lib/slanger/redis.rb', line 33

def hdel(*arg)
  send_command :hdel, *arg
end

#hgetall(*arg) ⇒ Object



37
38
39
# File 'lib/slanger/redis.rb', line 37

def hgetall(*arg)
  send_command :hgetall, *arg
end

#hincrby(*arg) ⇒ Object



25
26
27
# File 'lib/slanger/redis.rb', line 25

def hincrby(*arg)
  send_command :hincrby, *arg
end

#hset(*arg) ⇒ Object



29
30
31
# File 'lib/slanger/redis.rb', line 29

def hset(*arg)
  send_command :hset, *arg
end

#new_connectionObject



62
63
64
# File 'lib/slanger/redis.rb', line 62

def new_connection
  EM::Hiredis.connect Slanger::Config.redis_address
end

#publish(*arg) ⇒ Object



41
42
43
44
45
46
# File 'lib/slanger/redis.rb', line 41

def publish(*arg)
  result = publish_event(:publish, *arg).errback { |e|
    p [:publisherror, "redis:#{Slanger::Config.redis_address}:#{e}"]
  }
  result
end

#publish_event(method, *args) ⇒ Object



48
49
50
# File 'lib/slanger/redis.rb', line 48

def publish_event(method, *args)
  publisher.send(method, *args)
end

#publisherObject



17
18
19
# File 'lib/slanger/redis.rb', line 17

def publisher
  @publisher ||= new_connection
end

#regular_connectionObject



13
14
15
# File 'lib/slanger/redis.rb', line 13

def regular_connection
  @regular_connection ||= new_connection
end

#send_command(method, *arg) ⇒ Object



21
22
23
# File 'lib/slanger/redis.rb', line 21

def send_command(method, *arg)
  regular_connection.send(method, *arg)
end

#subscriberObject



52
53
54
55
56
57
58
59
60
# File 'lib/slanger/redis.rb', line 52

def subscriber
  @subscriber ||= new_connection.pubsub.tap do |c|
    c.on(:message) do |channel, message|
      message = Oj.strict_load(message)
      c = Channel.from message["channel"]
      c.dispatch message, channel
    end
  end
end