Sha256: 7691926ecb086b0a477df366b85cf96f8ac3af24e3d72dc1bf9f61ed40e13672

Contents?: true

Size: 966 Bytes

Versions: 1

Compression:

Stored size: 966 Bytes

Contents

module FFI
  module HiredisVip
    class Sadd
      def initialize(client)
        @client = client
      end

      def sadd(key, *values)
        reply = nil
        values = values.flatten
        number_of_values = values.size
        command = "SADD %b#{' %b' * number_of_values}"
        command_args = [ :pointer, key, :size_t, key.size ]
        values.each do |value|
          command_args << :pointer << value << :size_t << value.size
        end

        synchronize do |connection|
          reply = @client.execute_command(connection, command, *command_args)
        end

        return nil if reply.nil? || reply.null?

        case reply[:type] 
        when :REDIS_REPLY_INTEGER
          reply[:integer]
        else
          0
        end
      end

      private

      def synchronize
        @client.synchronize do |connection|
          yield(connection)
        end
      end

    end # class Sadd
  end # module HiredisVip
end # module FFI

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffi-hiredis_vip-0.1.0.pre3 lib/ffi/hiredis_vip/sadd.rb