Class: Moneta::Adapters::Client
- Inherits:
-
Object
- Object
- Moneta::Adapters::Client
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/client.rb
Overview
Moneta client backend
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
-
#close ⇒ Object
Explicitly close the store.
-
#create(key, value, options = {}) ⇒ Boolean
Atomically sets a key to value if it’s not set.
-
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value.
- #features ⇒ Object
-
#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, included, #supports?
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
14 15 16 17 |
# File 'lib/moneta/adapters/client.rb', line 14 def initialize( = {}) @socket = [:socket] ? UNIXSocket.open([:socket]) : TCPSocket.open([:host] || '127.0.0.1', [:port] || 9000) end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
57 58 59 60 61 |
# File 'lib/moneta/adapters/client.rb', line 57 def clear( = {}) write(:clear, ) read self end |
#close ⇒ Object
Explicitly close the store
64 65 66 67 |
# File 'lib/moneta/adapters/client.rb', line 64 def close @socket.close nil end |
#create(key, value, options = {}) ⇒ Boolean
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Atomically sets a key to value if it’s not set.
51 52 53 54 |
# File 'lib/moneta/adapters/client.rb', line 51 def create(key, value, = {}) write(:create, key, value, ) read end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
39 40 41 42 |
# File 'lib/moneta/adapters/client.rb', line 39 def delete(key, = {}) write(:delete, key, ) read end |
#features ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/moneta/adapters/client.rb', line 70 def features @features ||= begin write(:features) read.freeze end 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.
45 46 47 48 |
# File 'lib/moneta/adapters/client.rb', line 45 def increment(key, amount = 1, = {}) write(:increment, key, amount, ) read end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
20 21 22 23 |
# File 'lib/moneta/adapters/client.rb', line 20 def key?(key, = {}) write(:key?, key, ) read end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
26 27 28 29 |
# File 'lib/moneta/adapters/client.rb', line 26 def load(key, = {}) write(:load, key, ) read end |
#store(key, value, options = {}) ⇒ Object
Store value with key
32 33 34 35 36 |
# File 'lib/moneta/adapters/client.rb', line 32 def store(key, value, = {}) write(:store, key, value, ) read value end |