Class: Moneta::Adapters::Client
- Inherits:
-
Object
- Object
- Moneta::Adapters::Client
- Defined in:
- lib/moneta/adapters/client.rb
Overview
Moneta client backend
Constant Summary
Constants included from Net
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
-
#close ⇒ Object
Explicitly close the store.
-
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value.
-
#increment(key, amount = 1, options = {}) ⇒ Object
Atomically increment integer value with key.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#key?(key, options = {}) ⇒ Boolean
Exists the value with key.
-
#load(key, options = {}) ⇒ Object
Fetch value with key.
-
#store(key, value, options = {}) ⇒ Object
Store value with key.
Methods included from Defaults
#[], #[]=, #decrement, #fetch
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Methods included from Net
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 |
# File 'lib/moneta/adapters/client.rb', line 15 def initialize( = {}) @socket = [:file] ? UNIXSocket.open([:file]) : TCPSocket.open([:host] || '127.0.0.1', [:port] || DEFAULT_PORT) end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
52 53 54 55 56 |
# File 'lib/moneta/adapters/client.rb', line 52 def clear( = {}) write(@socket, [:clear, ]) read_result self end |
#close ⇒ Object
Explicitly close the store
59 60 61 62 |
# File 'lib/moneta/adapters/client.rb', line 59 def close @socket.close nil end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
40 41 42 43 |
# File 'lib/moneta/adapters/client.rb', line 40 def delete(key, = {}) write(@socket, [:delete, key, ]) read_result end |
#increment(key, amount = 1, options = {}) ⇒ Object
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Atomically increment integer value with key
This method also accepts negative amounts.
46 47 48 49 |
# File 'lib/moneta/adapters/client.rb', line 46 def increment(key, amount = 1, = {}) write(@socket, [:increment, key, amount, ]) read_result end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
21 22 23 24 |
# File 'lib/moneta/adapters/client.rb', line 21 def key?(key, = {}) write(@socket, [:key?, key, ]) read_result end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
27 28 29 30 |
# File 'lib/moneta/adapters/client.rb', line 27 def load(key, = {}) write(@socket, [:load, key, ]) read_result end |
#store(key, value, options = {}) ⇒ Object
Store value with key
33 34 35 36 37 |
# File 'lib/moneta/adapters/client.rb', line 33 def store(key, value, = {}) write(@socket, [:store, key, value, ]) read_result value end |