Class: Yup::State::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/yup/state/redis.rb

Defined Under Namespace

Classes: RequestForwarder

Instance Method Summary collapse

Constructor Details

#initialize(uri, forward_to) ⇒ Redis

Returns a new instance of Redis.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/yup/state/redis.rb', line 11

def initialize(uri, forward_to)
  @uri = URI.parse(uri)
  @ns  = @uri.path[1..-1]
  @ns  = "yup-#{VERSION}" if @ns.empty?
  @ns << ":#{forward_to}"

  @logger = Yup.logger.clone
  @logger.progname = "Yup::State::Redis"

  @redis_backend = ::Redis.new(:host => @uri.host, :port => @uri.port)
  @redis         = ::Redis::Namespace.new(@ns, :redis => @redis_backend)
end

Instance Method Details

#bpopObject



34
35
36
37
38
# File 'lib/yup/state/redis.rb', line 34

def bpop
  _, data = @redis.brpop("requests", :timeout => 0)
  @logger.debug { "Bpoped: #{data.strip}" }
  data
end

#disposeObject



40
41
# File 'lib/yup/state/redis.rb', line 40

def dispose
end

#push(data) ⇒ Object



24
25
26
27
# File 'lib/yup/state/redis.rb', line 24

def push(data)
  @logger.debug { "Push: #{data}" }
  @redis.lpush("requests", data)
end

#pushback(data) ⇒ Object



29
30
31
32
# File 'lib/yup/state/redis.rb', line 29

def pushback(data)
  @logger.debug { "Push back: #{data}" }
  @redis.lpush("requests", data)
end