Class: Moneta::Adapters::Client
- Inherits:
-
Base
- Object
- Base
- Moneta::Adapters::Client
show all
- Includes:
- Net
- Defined in:
- lib/moneta/adapters/client.rb
Overview
Constant Summary
Constants included
from Net
Net::DEFAULT_PORT
Instance Method Summary
collapse
Methods included from Net
#pack, #read, #write
Methods inherited from Base
#[], #[]=, #decrement, #fetch
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Client
16
17
18
19
|
# File 'lib/moneta/adapters/client.rb', line 16
def initialize(options = {})
@socket = options[:file] ? UNIXSocket.open(options[:file]) :
TCPSocket.open(options[:host] || '127.0.0.1', options[:port] || DEFAULT_PORT)
end
|
Instance Method Details
#clear(options = {}) ⇒ Object
47
48
49
50
51
|
# File 'lib/moneta/adapters/client.rb', line 47
def clear(options = {})
write(@socket, [:clear, options])
read_result
self
end
|
#close ⇒ Object
53
54
55
56
|
# File 'lib/moneta/adapters/client.rb', line 53
def close
@socket.close
nil
end
|
#delete(key, options = {}) ⇒ Object
37
38
39
40
|
# File 'lib/moneta/adapters/client.rb', line 37
def delete(key, options = {})
write(@socket, [:delete, key, options])
read_result
end
|
#increment(key, amount = 1, options = {}) ⇒ Object
42
43
44
45
|
# File 'lib/moneta/adapters/client.rb', line 42
def increment(key, amount = 1, options = {})
write(@socket, [:increment, key, amount, options])
read_result
end
|
#key?(key, options = {}) ⇒ Boolean
21
22
23
24
|
# File 'lib/moneta/adapters/client.rb', line 21
def key?(key, options = {})
write(@socket, [:key?, key, options])
read_result
end
|
#load(key, options = {}) ⇒ Object
26
27
28
29
|
# File 'lib/moneta/adapters/client.rb', line 26
def load(key, options = {})
write(@socket, [:load, key, options])
read_result
end
|
#store(key, value, options = {}) ⇒ Object
31
32
33
34
35
|
# File 'lib/moneta/adapters/client.rb', line 31
def store(key, value, options = {})
write(@socket, [:store, key, value, options])
read_result
value
end
|