Sha256: e88eb6fb7ae56707415d1183b94af2915f5492c89ab8edf8770695dc2845b506

Contents?: true

Size: 769 Bytes

Versions: 7

Compression:

Stored size: 769 Bytes

Contents

require "redis"
require "json"

module Socrates
  module Storage
    class MemoryStorage
      def initialize
        @storage = {}
      end

      def has_key?(key)
        @storage.has_key? key
      end

      def clear(key)
        @storage.delete key
      end

      def get(key)
        @storage[key]
      end

      def put(key, value)
        @storage[key] = value
      end
    end

    class RedisStorage
      def initialize(url: "redis://localhost")
        @redis = Redis.new(url: url)
      end

      def has_key?(key)
        @redis.exists(key)
      end

      def clear(key)
        @redis.del key
      end

      def get(key)
        @redis.get(key)
      end

      def put(key, value)
        @redis.set(key, value)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
socrates-0.1.7 lib/socrates/storage/storage.rb
socrates-0.1.6 lib/socrates/storage/storage.rb
socrates-0.1.4 lib/socrates/storage/storage.rb
socrates-0.1.3 lib/socrates/storage/storage.rb
socrates-0.1.2 lib/socrates/storage/storage.rb
socrates-0.1.1 lib/socrates/storage/storage.rb
socrates-0.1.0 lib/socrates/storage/storage.rb