Sha256: a45fc0fd7231eff75ccad0c9612c44b8ff9a585de0925a2e5951be9b51a69d39

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

require 'dalli'

module SlackBotManager
  module Storage
    class Dalli
      attr_accessor :connection

      def initialize(options)
        if options.is_a?(Dalli)
          @connecton = options
        else
          servers = options.delete(:servers)
          @connection = ::Dalli::Client.new(servers, options)
        end
      end

      def pipeline(&block)
        yield block
      end

      def get_all(type)
        connection.get(type) || {}
      end

      def get(type, key)
        connection.get(type).try(key)
      end

      def set(type, key, val)
        obj = get_all(type).merge(key => val)
        connection.set(type, obj)
      end

      def multiset(type, *args)
        vals = args.extract_options!
        obj = get_all(type).merge(vals)
        connection.set(type, obj)
      end

      def delete(type, key)
        obj = get_all(type)
        obj.delete(key)
        connection.set(type, obj)
      end

      def delete_all(type)
        connection.delete(type)
      end

      # def expire(key, len)
      #   connection.expire(key, len)
      # end

      # def exists(type)
      #   connection.exists(key)
      # end

      # def incrby(type, key, incr=1)
      #   # TODO
      # end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
slack-bot-manager-0.1.0pre5 lib/slack-bot-manager/storage/dalli.rb
slack-bot-manager-0.1.0pre4 lib/slack-bot-manager/storage/dalli.rb
slack-bot-manager-0.1.0pre3 lib/slack-bot-manager/storage/dalli.rb
slack-bot-manager-0.1.0pre2 lib/slack-bot-manager/manager/storage/dalli.rb