Sha256: 5a2e1c408549b0398217ac8256f6308f212adf66f0a156b959ee13f4f81e7e59

Contents?: true

Size: 976 Bytes

Versions: 1

Compression:

Stored size: 976 Bytes

Contents

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

      def sadd(key, *values)
        values = values.flatten
        number_added_to_set = 0
        command = "SADD %b %b"

        values.each do |value|
          command_args = [ :string, key, :size_t, key.size, :string, value, :size_t, value.size ]
          synchronize do |connection|
            reply = ::FFI::HiredisVip::Core.command(connection, command, *command_args)

            next if reply.nil? || reply.null?

            case reply[:type] 
            when :REDIS_REPLY_INTEGER
              number_added_to_set = number_added_to_set + reply[:integer]
            end
          end
        end

        number_added_to_set
      end

      private

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

    end # class SaddBefore24
  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/sadd_before_2_4.rb