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.



3
4
5
6
# File 'lib/kv.rb', line 3

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

Instance Method Details

#delete(key) ⇒ Object



20
21
22
23
24
# File 'lib/kv.rb', line 20

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

#exists(key) ⇒ Object



38
39
40
41
42
# File 'lib/kv.rb', line 38

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

#get(key) ⇒ Object



14
15
16
17
18
# File 'lib/kv.rb', line 14

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

#itemsObject



32
33
34
35
36
# File 'lib/kv.rb', line 32

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

#keysObject



26
27
28
29
30
# File 'lib/kv.rb', line 26

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

#purgeObject



44
45
46
47
48
49
50
# File 'lib/kv.rb', line 44

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

#set(key, value) ⇒ Object



8
9
10
11
12
# File 'lib/kv.rb', line 8

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