class Moneta::Adapters::KyotoCabinet
KyotoCabinet
backend @api public
Public Instance Methods
close()
click to toggle source
(see Proxy#close
)
# File lib/moneta/adapters/kyotocabinet.rb, line 38 def close backend.close nil end
create(key, value, options = {})
click to toggle source
(see Proxy#create
)
# File lib/moneta/adapters/kyotocabinet.rb, line 33 def create(key, value, options = {}) backend.add(key, value) end
delete(key, options = {})
click to toggle source
(see Proxy#delete
)
# File lib/moneta/adapters/kyotocabinet.rb, line 28 def delete(key, options = {}) backend.seize(key) end
each_key() { |arr| ... }
click to toggle source
(see Proxy#each_key
)
# File lib/moneta/adapters/kyotocabinet.rb, line 44 def each_key return enum_for(:each_key) { backend.count } unless block_given? backend.each_key { |arr| yield arr[0] } self end
increment(key, amount = 1, options = {})
click to toggle source
(see Proxy#increment
)
# File lib/moneta/adapters/kyotocabinet.rb, line 51 def increment(key, amount = 1, options = {}) ret = nil success = backend.accept(key) do |_, value| ret = if value Integer(value) + amount else amount end ret.to_s end raise backend.error unless success ret end
key?(key, options = {})
click to toggle source
(see Proxy#key?
)
# File lib/moneta/adapters/kyotocabinet.rb, line 23 def key?(key, options = {}) backend.check(key) >= 0 end
merge!(pairs, options = {}) { |key, existing, new_value| ... }
click to toggle source
(see Proxy#merge!
)
# File lib/moneta/adapters/kyotocabinet.rb, line 79 def merge!(pairs, options = {}) hard = options.key?(:hard) ? options[:hard] : false atomic = options.key?(:atomic) ? options[:atomic] : true success = if block_given? backend.transaction(hard) do existing = slice(*pairs.map { |k, _| k }, **options) pairs = pairs.map do |key, new_value| if existing.key?(key) [key, yield(key, existing[key], new_value)] else [key, new_value] end end backend.set_bulk(pairs.to_h, atomic) >= 0 end else backend.set_bulk(pairs.to_h, atomic) >= 0 end raise backend.error unless success self end
slice(*keys, atomic: true, **options)
click to toggle source
(see Proxy#slice
)
# File lib/moneta/adapters/kyotocabinet.rb, line 68 def slice(*keys, atomic: true, **options) backend.get_bulk(keys, atomic) end
values_at(*keys, **options)
click to toggle source
(see Proxy#values_at
)
# File lib/moneta/adapters/kyotocabinet.rb, line 73 def values_at(*keys, **options) hash = slice(*keys, **options) keys.map { |key| hash[key] } end