Class: Metricstore::CouchbaseClient
- Inherits:
-
Object
- Object
- Metricstore::CouchbaseClient
- Defined in:
- lib/metricstore/couchbase_client.rb
Overview
Internal class. Use this class outside the gem at your own risk.
Instance Method Summary collapse
-
#add(key, value, opts = {}) ⇒ Object
key: a string value: a marshalable object options: :ttl => Time-to-live (number of seconds from now).
-
#fetch(key, opts = {}) ⇒ Object
key: a string returns: [value, cas_version_id], or nil if the key doesn’t exist.
-
#increment(key, delta, opts = {}) ⇒ Object
key: a string delta: an integer options: :ttl => Time-to-live (number of seconds from now).
-
#initialize(*args, &callback) ⇒ CouchbaseClient
constructor
A new instance of CouchbaseClient.
-
#set(key, value, opts = {}) ⇒ Object
key: a string value: a marshalable object options: :ttl => Time-to-live (number of seconds from now).
Constructor Details
#initialize(*args, &callback) ⇒ CouchbaseClient
Returns a new instance of CouchbaseClient.
7 8 9 10 |
# File 'lib/metricstore/couchbase_client.rb', line 7 def initialize(*args, &callback) super @connection = Couchbase.connect(*args, &callback) end |
Instance Method Details
#add(key, value, opts = {}) ⇒ Object
key: a string value: a marshalable object options:
:ttl => Time-to-live (number of seconds from now).
returns: cas_version_id, or nil if the key already exists.
29 30 31 32 33 34 35 |
# File 'lib/metricstore/couchbase_client.rb', line 29 def add(key, value, opts={}) = {} .merge(:ttl => convert_ttl(opts[:ttl])) if opts.include?(:ttl) connection.add(key, value, opts) rescue Couchbase::Error::KeyExists => e nil end |
#fetch(key, opts = {}) ⇒ Object
key: a string returns: [value, cas_version_id], or nil if the key doesn’t exist.
54 55 56 57 58 59 |
# File 'lib/metricstore/couchbase_client.rb', line 54 def fetch(key, opts={}) = {:extended => true, :quiet => true} .merge(:ttl => convert_ttl(opts[:ttl])) if opts.include?(:ttl) value, flags, cas = connection.get(key, ) value.nil? ? nil : [value, cas] end |
#increment(key, delta, opts = {}) ⇒ Object
key: a string delta: an integer options:
:ttl => Time-to-live (number of seconds from now).
returns: [value, cas_version_id]
17 18 19 20 21 22 |
# File 'lib/metricstore/couchbase_client.rb', line 17 def increment(key, delta, opts={}) = {:initial => delta, :extended => true} .merge(:ttl => convert_ttl(opts[:ttl])) if opts.include?(:ttl) value, flags, cas = connection.incr(key, delta, ) [value, cas] end |
#set(key, value, opts = {}) ⇒ Object
key: a string value: a marshalable object options:
:ttl => Time-to-live (number of seconds from now).
:cas => a version id (for optimistic concurrency control)
returns: cas_version_id, or nil if the key already exists.
43 44 45 46 47 48 49 50 |
# File 'lib/metricstore/couchbase_client.rb', line 43 def set(key, value, opts={}) = {} .merge(:ttl => convert_ttl(opts[:ttl])) if opts.include?(:ttl) .merge(:cas => opts[:cas]) if opts.include?(:cas) connection.set(key, value, opts) rescue Couchbase::Error::KeyExists => e nil end |