class Moneta::Adapters::Client
Moneta
client backend @api public
Public Instance Methods
clear(options = {})
click to toggle source
(see Proxy#clear
)
# File lib/moneta/adapters/client.rb, line 60 def clear(options = {}) write(:clear, options) read_msg self end
close()
click to toggle source
(see Proxy#close
)
# File lib/moneta/adapters/client.rb, line 67 def close backend.close nil end
create(key, value, options = {})
click to toggle source
(see Proxy#create
)
# File lib/moneta/adapters/client.rb, line 54 def create(key, value, options = {}) write(:create, key, value, options) read_msg end
delete(key, options = {})
click to toggle source
(see Proxy#delete
)
# File lib/moneta/adapters/client.rb, line 42 def delete(key, options = {}) write(:delete, key, options) read_msg end
each_key() { |result| ... }
click to toggle source
(see Proxy#each_key
)
# File lib/moneta/adapters/client.rb, line 73 def each_key raise NotImplementedError, 'each_key is not supported' unless supports?(:each_key) return enum_for(:each_key) unless block_given? begin write(:each_key) yield_break = false loop do write('NEXT') # A StopIteration error will be raised by this call if the server # reached the end of the enumeration. This will stop the loop # automatically. result = read_msg # yield_break will be true in the ensure block (below) if anything # happened during the yield to stop further enumeration. yield_break = true yield result yield_break = false end ensure write('BREAK') if yield_break read_msg # nil return from each_key end self end
features()
click to toggle source
(see Default#features)
# File lib/moneta/adapters/client.rb, line 104 def features @features ||= begin write(:features) read_msg.freeze end end
increment(key, amount = 1, options = {})
click to toggle source
(see Proxy#increment
)
# File lib/moneta/adapters/client.rb, line 48 def increment(key, amount = 1, options = {}) write(:increment, key, amount, options) read_msg end
key?(key, options = {})
click to toggle source
(see Proxy#key?
)
# File lib/moneta/adapters/client.rb, line 23 def key?(key, options = {}) write(:key?, key, options) read_msg end
load(key, options = {})
click to toggle source
(see Proxy#load
)
# File lib/moneta/adapters/client.rb, line 29 def load(key, options = {}) write(:load, key, options) read_msg end
store(key, value, options = {})
click to toggle source
(see Proxy#store
)
# File lib/moneta/adapters/client.rb, line 35 def store(key, value, options = {}) write(:store, key, value, options) read_msg value end
Private Instance Methods
read(bytes)
click to toggle source
# File lib/moneta/adapters/client.rb, line 121 def read(bytes) received = backend.read(bytes) raise EOFError, "Server closed socket" unless received && received.bytesize == bytes received end
read_msg()
click to toggle source
# File lib/moneta/adapters/client.rb, line 134 def read_msg size = read(4).unpack1('N') result = Marshal.load(read(size)) raise result if Exception === result result end
write(*args)
click to toggle source
# File lib/moneta/adapters/client.rb, line 114 def write(*args) s = Marshal.dump(args) backend.write([s.bytesize].pack('N') << s) end