Sha256: 128387b6ef7c96c17e1cd826e75e442cb9497fb64a6bf7f50a119b13f4a95ee9

Contents?: true

Size: 842 Bytes

Versions: 2

Compression:

Stored size: 842 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, _, expire: false)
        ret = @client.multi do |multi|
          if expire
            multi.setex(@key, @options[:ttl], newval)
          else
            multi.set(@key, newval)
          end
        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)
        set(val, nil)
        nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
suo-0.3.4 lib/suo/client/redis.rb
suo-0.3.3 lib/suo/client/redis.rb