0xSina
0xSina

Reputation: 21553

Redis-rb client queue

I am going to use this client library: https://github.com/ezmobius/redis-rb

In the github page, it doesn't say anything about queues. Is this behaviour by default? When I add a key/value to red is, does it use a queue datastrucutre automatically?

Also, redis has this BLPOP and BRPOP which allow you to block until a new value appears in the queue. Is this available in redis-rb? If not, is there library I can use that support that?

Upvotes: 2

Views: 2027

Answers (3)

rurabe
rurabe

Reputation: 447

I've been using an array that gets encoded and parsed in JSON:

begin
  queue = JSON.parse( REDIS.get(:some_queue) )
  item = queue.shift
  REDIS.set(:some_queue,queue.to_json)
  Do::Work.new(item)
rescue #just in case it fails
  queue = JSON.parse( REDIS.get(:lots_queue) )
  queue.prepend(id)
  REDIS.set(:lots_queue,queue.to_json)
end

Upvotes: 0

djanowski
djanowski

Reputation: 5858

Yes, the gem fully supports everything Redis has to offer.

Check for instance the documentation on BLPOP.

There's also this example on working with lists.

Upvotes: 1

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230336

Surely, redis-rb supports all that you're asking for. (BLPOP / BRPOP / LPUSH / LPOP).

ree-1.8.7-2011.03 :001 > REDIS.methods.sort

=> ["==", "===", "=~", "[]", "[]=", "id", "is_a", "metaclass", "send", "`", "acts_like?", "append", "as_json", "auth", "b64encode", "bgrewriteaof", "bgsave", "blank?", "blpop", "breakpoint", "brpop", "brpoplpush", "class", "class_eval", "client", "clone", "config", "copy_instance_variables_from", "dbsize", "debug", "debugger", "decode64", "decode_b", "decr", "decrby", "del", "discard", "display", "do_or_do_not", "dup", "duplicable?", "echo", "enable_warnings", "encode64", "enum_for", "eql?", "equal?", "exec", "exists", "expects", "expire", "expireat", "extend", "flushall", "flushdb", "freeze", "frozen?", "gem", "get", "getbit", "getrange", "getset", "hash", "hdel", "hexists", "hget", "hgetall", "hincrby", "hkeys", "hlen", "hmget", "hmset", "hset", "hsetnx", "html_safe?", "hvals", "id", "incr", "incrby", "info", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_values", "instance_variable_defined?", "instance_variable_get", "instance_variable_names", "instance_variable_set", "instance_variables", "is_a?", "is_haml?", "ivar", "keys", "kind_of?", "lastsave", "lindex", "linsert", "llen", "load", "load_dependency", "lpop", "lpush", "lpushx", "lrange", "lrem", "lset", "ltrim", "mapped_hmget", "mapped_hmset", "mapped_mget", "mapped_mset", "mapped_msetnx", "method", "method_exists?", "method_missing", "methods", "mget", "mocha", "mocha_inspect", "mon_enter", "mon_exit", "mon_synchronize", "mon_try_enter", "monitor", "move", "mset", "msetnx", "multi", "new_cond", "nil?", "object_id", "persist", "ping", "pipelined", "presence", "present?", "private_methods", "protected_methods", "psubscribe", "public_methods", "publish", "punsubscribe", "quit", "randomkey", "rename", "renamenx", "require", "require_association", "require_dependency", "require_library_or_gem", "require_or_load", "reset_mocha", "respond_to?", "returning", "rpop", "rpoplpush", "rpush", "rpushx", "sadd", "save", "scard", "sdiff", "sdiffstore", "select", "send", "set", "setbit", "setex", "setnx", "setrange", "shutdown", "silence_stderr", "silence_stream", "silence_warnings", "singleton_class", "singleton_methods", "sinter", "sinterstore", "sismember", "slaveof", "smembers", "smove", "sort", "spop", "srandmember", "srem", "strlen", "stubba_method", "stubba_object", "stubs", "subscribe", "subscribed?", "substr", "sunion", "sunionstore", "suppress", "suppress_warnings", "sync", "synchronize", "taguri", "taguri=", "taint", "tainted?", "tap", "to_a", "to_enum", "to_json", "to_matcher", "to_param", "to_query", "to_s", "to_yaml", "to_yaml_properties", "to_yaml_style", "try", "try_mon_enter", "ttl", "type", "unloadable", "unstub", "unsubscribe", "untaint", "unwatch", "watch", "with_options", "with_warnings", "without_reconnect", "zadd", "zcard", "zcount", "zincrby", "zinterstore", "zrange", "zrangebyscore", "zrank", "zrem", "zremrangebyrank", "zremrangebyscore", "zrevrange", "zrevrangebyscore", "zrevrank", "zscore", "zunionstore"]

Upvotes: 0

Related Questions