Sha256: 446be29b49e6f92f6525bb79ca7828d0ee7bc4cf934d56c174c7e64c88689053

Contents?: true

Size: 719 Bytes

Versions: 3

Compression:

Stored size: 719 Bytes

Contents

module Suo
  module Client
    class Redis < Base
      OK_STR = "OK".freeze

      def initialize(key, options = {})
        options[:client] ||= ::Redis.new(options[:connection] || {})
        super
      end

      def clear
        @client.del(@key)
      end

      private

      def get
        [@client.get(@key), nil]
      end

      def set(newval, _)
        ret = @client.multi do |multi|
          multi.set(@key, newval)
        end

        ret && ret[0] == OK_STR
      end

      def synchronize
        @client.watch(@key) do
          yield
        end
      ensure
        @client.unwatch
      end

      def initial_set(val = BLANK_STR)
        @client.set(@key, val)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
suo-dependless-0.3.2 lib/suo/client/redis.rb
suo-0.3.2 lib/suo/client/redis.rb
suo-0.3.1 lib/suo/client/redis.rb