Class: Streamdal::KeyValue

Inherits:
Object
  • Object
show all
Defined in:
lib/kv.rb

Instance Method Summary collapse

Constructor Details

#initializeKeyValue

Returns a new instance of KeyValue.



5
6
7
8
# File 'lib/kv.rb', line 5

def initialize
  @kvs = {}
  @mtx = Mutex.new
end

Instance Method Details

#delete(key) ⇒ Object



22
23
24
25
26
# File 'lib/kv.rb', line 22

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

#exists(key) ⇒ Object



40
41
42
43
44
# File 'lib/kv.rb', line 40

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

#get(key) ⇒ Object



16
17
18
19
20
# File 'lib/kv.rb', line 16

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

#itemsObject



34
35
36
37
38
# File 'lib/kv.rb', line 34

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

#keysObject



28
29
30
31
32
# File 'lib/kv.rb', line 28

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

#purgeObject



46
47
48
49
50
51
52
# File 'lib/kv.rb', line 46

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

#set(key, value) ⇒ Object



10
11
12
13
14
# File 'lib/kv.rb', line 10

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