Class: Ccp::Kvs::Tokyo::Cabinet
Constant Summary
StateMachine::CLOSED, StateMachine::READABLE, StateMachine::WRITABLE
Instance Method Summary
collapse
#C!, #R, #R!, #W, #W!, #__close__, #close, #locker_info, #open, #state, #touch
Methods inherited from Base
#info, #path
Methods included from Core
#[], #[]=, #close, #codec, #codec!, #decode, #encode, #ext, included, #open, #out, #put, #source, #touch
Constructor Details
#initialize(source) ⇒ Cabinet
Returns a new instance of Cabinet.
7
8
9
10
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 7
def initialize(source)
@source = source
@db = HDB.new
end
|
Instance Method Details
#count ⇒ Object
50
51
52
53
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 50
def count
tryR("count")
return @db.rnum
end
|
#del(k) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 36
def del(k)
tryW("del")
v = @db[k.to_s]
if v
if @db.delete(k.to_s)
return decode(v)
else
tokyo_error!("del(%s): " % k)
end
else
return nil
end
end
|
#each(&block) ⇒ Object
72
73
74
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 72
def each(&block)
each_pair(&block)
end
|
#each_key(&block) ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 82
def each_key(&block)
tryR("each_key")
@db.iterinit or tokyo_error!("each_key: ")
while key = @db.iternext
block.call(key)
end
end
|
#each_keys(&block) ⇒ Object
90
91
92
93
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 90
def each_keys(&block)
STDERR.puts "DEPRECATION WARNING: #{self.class}#each_keys is deprecated and will be removed in 0.4.0, use each_key instead"
each_key(&block)
end
|
#each_pair(&block) ⇒ Object
76
77
78
79
80
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 76
def each_pair(&block)
each_key do |key|
block.call(key, get(key))
end
end
|
#first ⇒ Object
109
110
111
112
113
114
115
116
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 109
def first
key = first_key
if key
return [key, get(key)]
else
return nil
end
end
|
#first_key ⇒ Object
103
104
105
106
107
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 103
def first_key
tryR("first_key")
@db.iterinit or tokyo_error!("first_key: ")
return @db.iternext
end
|
#get(k) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 15
def get(k)
tryR("get")
v = @db[k.to_s]
if v
return decode(v)
else
if @db.ecode == HDB::ENOREC
return nil
else
tokyo_error!("get(%s): " % k)
end
end
end
|
#keys ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 95
def keys
array = []
each_key do |key|
array << key
end
return array
end
|
#read! ⇒ Object
bulk operations (not DRY but fast)
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 58
def read!
tryR("read!")
hash = {}
@db.iterinit or tokyo_error!("read!: ")
while k = @db.iternext
v = @db.get(k) or tokyo_error!("get(%s): " % k)
hash[k] = decode(v)
end
return hash
end
|
#set(k, v) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/ccp/kvs/tokyo/cabinet.rb', line 29
def set(k,v)
tryW("set")
val = encode(v)
@db[k.to_s] = val or
tokyo_error!("set(%s): " % k)
end
|