Sha256: f7cccc79937affe2face3f64c4ffd7f4d342cdeb28bbb7f1ebcb9050d3d9ce2b

Contents?: true

Size: 747 Bytes

Versions: 1

Compression:

Stored size: 747 Bytes

Contents

module Streamdal
  class KeyValue
    def initialize
      @kvs = {}
      @mtx = Mutex.new
    end

    def set(key, value)
      @mtx.synchronize do
        @kvs[key] = value
      end
    end

    def get(key)
      @mtx.synchronize do
        @kvs[key]
      end
    end

    def delete(key)
      @mtx.synchronize do
        @kvs.delete(key)
      end
    end

    def keys
      @mtx.synchronize do
        @kvs.keys
      end
    end

    def items
      @mtx.synchronize do
        @kvs.values
      end
    end

    def exists(key)
      @mtx.synchronize do
        @kvs.key?(key)
      end
    end

    def purge
      @mtx.synchronize do
        num_keys = @kvs.keys.length
        @kvs = {}
        num_keys
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
streamdal-0.0.1 lib/kv.rb