Sha256: 14d291476b2e71c89742ad0163c89e771631afa0914697cc7e3a01eb607c19d5
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
module FFI module HiredisVip class Mget def initialize(client) @client = client end def mget(*keys) reply = nil keys = keys.flatten command = "MGET" command_args = [] keys.each do |key| command << " %b" command_args << :string << key << :size_t << key.size end synchronize do |connection| reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args) end return nil if reply.nil? || reply.null? # TODO: more error checking here? what is correct response on nothing? case reply[:type] when :REDIS_REPLY_ARRAY mget_results_to_array(reply) else [] end end private def mget_results_to_array(array_reply) mget_results = [] 0.upto(array_reply[:elements] - 1) do |element_number| result = ::FFI::HiredisVip::Core.redisReplyElement(array_reply, element_number) case result[:type] when :REDIS_REPLY_STRING mget_results << result[:str] when :REDIS_REPLY_NIL mget_results << nil end end mget_results end def synchronize @client.synchronize do |connection| yield(connection) end end end # class Mget end # module HiredisVip end # module FFI
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ffi-hiredis_vip-0.1.0.pre1 | lib/ffi/hiredis_vip/mget.rb |