/usr/lib/ruby/vendor_ruby/moneta/adapters/client.rb is in ruby-moneta 0.7.20-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | require 'socket'
module Moneta
module Adapters
# Moneta client backend
# @api public
class Client
include Defaults
# @param [Hash] options
# @option options [Integer] :port (9000) TCP port
# @option options [String] :host ('127.0.0.1') Hostname
# @option options [String] :socket Unix socket file name as alternative to `:port` and `:host`
def initialize(options = {})
@socket = options[:socket] ? UNIXSocket.open(options[:socket]) :
TCPSocket.open(options[:host] || '127.0.0.1', options[:port] || 9000)
end
# (see Proxy#key?)
def key?(key, options = {})
write(:key?, key, options)
read
end
# (see Proxy#load)
def load(key, options = {})
write(:load, key, options)
read
end
# (see Proxy#store)
def store(key, value, options = {})
write(:store, key, value, options)
read
value
end
# (see Proxy#delete)
def delete(key, options = {})
write(:delete, key, options)
read
end
# (see Proxy#increment)
def increment(key, amount = 1, options = {})
write(:increment, key, amount, options)
read
end
# (see Proxy#create)
def create(key, value, options = {})
write(:create, key, value, options)
read
end
# (see Proxy#clear)
def clear(options = {})
write(:clear, options)
read
self
end
# (see Proxy#close)
def close
@socket.close
nil
end
# (see Default#features)
def features
@features ||=
begin
write(:features)
read.freeze
end
end
private
def write(*args)
s = Marshal.dump(args)
@socket.write([s.bytesize].pack('N') << s)
end
def read
size = @socket.read(4).unpack('N').first
result = Marshal.load(@socket.read(size))
raise result if Exception === result
result
end
end
end
end
|