Class: Barrister::RedisTransport
- Inherits:
-
Object
- Object
- Barrister::RedisTransport
- Defined in:
- lib/barrister-redis.rb
Instance Method Summary collapse
-
#initialize(list_name, options = {}) ⇒ RedisTransport
constructor
A new instance of RedisTransport.
- #request(message) ⇒ Object
Constructor Details
#initialize(list_name, options = {}) ⇒ RedisTransport
Returns a new instance of RedisTransport.
9 10 11 12 13 14 15 16 |
# File 'lib/barrister-redis.rb', line 9 def initialize(list_name, ={}) = { database_url: 'redis://localhost:6379' }.merge() @list_name = list_name @client = ::Redis.connect url: [:database_url] end |
Instance Method Details
#request(message) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/barrister-redis.rb', line 18 def request() # reply-to tells the server where we'll be listening request = { 'reply_to' => 'reply-' + SecureRandom.uuid, 'message' => } # insert our request at the head of the list @client.lpush(@list_name, JSON.generate(request)) # pop last element off our list in a blocking fashion channel, response = @client.brpop(request['reply_to'], timeout=30) JSON.parse(response)['message'] end |