Class: Couchbase::Bucket
- Inherits:
-
Object
- Object
- Couchbase::Bucket
- Includes:
- Async, Operations
- Defined in:
- lib/couchbase/bucket.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ type: nil, quiet: false, hostname: 'localhost', port: 8091, pool: 'default', bucket: 'default', password: '', engine: nil, default_ttl: 0, default_arithmetic_init: 0, default_flags: 0, default_format: :document, default_observe_timeout: 2_500_000, on_error: nil, on_connect: nil, timeout: 0, environment: nil, key_prefix: nil, node_list: nil, destroying: 0, connected: 0, on_connect_proc: nil, connected: false }.freeze
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#default_arithmetic_init ⇒ Object
Returns the value of attribute default_arithmetic_init.
-
#default_format ⇒ Object
Returns the value of attribute default_format.
-
#default_ttl ⇒ Object
Returns the value of attribute default_ttl.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#key_prefix ⇒ Object
readonly
Returns the value of attribute key_prefix.
-
#password ⇒ Object
Returns the value of attribute password.
-
#pool ⇒ Object
Returns the value of attribute pool.
-
#port ⇒ Object
Returns the value of attribute port.
-
#quiet ⇒ Object
Returns the value of attribute quiet.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#transcoder ⇒ Object
Returns the value of attribute transcoder.
-
#transcoders ⇒ Object
Returns the value of attribute transcoders.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #async_flush ⇒ Object
- #authority ⇒ Object
- #base_url ⇒ Object
-
#cas(key, options = {}) {|value| ... } ⇒ Fixnum
(also: #compare_and_swap)
Compare and swap value.
- #connect ⇒ Object (also: #reconnect)
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
-
#flush {|ret| ... } ⇒ true
Delete contents of the bucket.
- #host ⇒ Object
-
#initialize(url = nil, options = {}) ⇒ Bucket
constructor
Initialize new Bucket.
- #on_connect(&block) ⇒ Object
- #on_error(&block) ⇒ Object
- #quiet? ⇒ Boolean
- #url ⇒ Object
- #version ⇒ Object
Methods included from Operations
Constructor Details
#initialize(url, options = {}) ⇒ Bucket #initialize(options = {}) ⇒ Bucket
Initialize new Bucket.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/couchbase/bucket.rb', line 157 def initialize(url = nil, = {}) = (url) = Couchbase.() = DEFAULT_OPTIONS.merge().merge() .each_pair do |key, value| instance_variable_set("@#{key}", value) end self.password = '' if self.password.nil? @transcoders = { document: Transcoder::Document.new, marshal: Transcoder::Marshal.new, plain: Transcoder::Plain.new } connect end |
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def bucket @bucket end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
42 43 44 |
# File 'lib/couchbase/bucket.rb', line 42 def client @client end |
#default_arithmetic_init ⇒ Object
Returns the value of attribute default_arithmetic_init.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def default_arithmetic_init @default_arithmetic_init end |
#default_format ⇒ Object
Returns the value of attribute default_format.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def default_format @default_format end |
#default_ttl ⇒ Object
Returns the value of attribute default_ttl.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def default_ttl @default_ttl end |
#hostname ⇒ Object
Returns the value of attribute hostname.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def hostname @hostname end |
#key_prefix ⇒ Object (readonly)
Returns the value of attribute key_prefix.
42 43 44 |
# File 'lib/couchbase/bucket.rb', line 42 def key_prefix @key_prefix end |
#password ⇒ Object
Returns the value of attribute password.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def password @password end |
#pool ⇒ Object
Returns the value of attribute pool.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def pool @pool end |
#port ⇒ Object
Returns the value of attribute port.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def port @port end |
#quiet ⇒ Object
Returns the value of attribute quiet.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def quiet @quiet end |
#timeout ⇒ Object
Returns the value of attribute timeout.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def timeout @timeout end |
#transcoder ⇒ Object
Returns the value of attribute transcoder.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def transcoder @transcoder end |
#transcoders ⇒ Object
Returns the value of attribute transcoders.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def transcoders @transcoders end |
#username ⇒ Object
Returns the value of attribute username.
38 39 40 |
# File 'lib/couchbase/bucket.rb', line 38 def username @username end |
Instance Method Details
#async_flush ⇒ Object
340 341 342 |
# File 'lib/couchbase/bucket.rb', line 340 def async_flush @client.flush end |
#authority ⇒ Object
206 207 208 |
# File 'lib/couchbase/bucket.rb', line 206 def "#{hostname}:#{port}" end |
#base_url ⇒ Object
210 211 212 |
# File 'lib/couchbase/bucket.rb', line 210 def base_url "http://#{authority}/pools" end |
#cas(key, options = {}) {|value| ... } ⇒ Fixnum Also known as: compare_and_swap
Compare and swap value.
Reads a key’s value from the server and yields it to a block. Replaces the key’s value with the result of the block as long as the key hasn’t been updated in the meantime, otherwise raises Error::KeyExists. CAS stands for “compare and swap”, and avoids the need for manual key mutexing. Read more info here:
In asynchronous mode it will yield result twice, first for Bucket#get with Result#operation equal to :get and second time for Bucket#set with Result#operation equal to :set.
312 313 314 315 316 |
# File 'lib/couchbase/bucket.rb', line 312 def cas(key, = {}) val, flags, ver = get(key, :extended => true) val = yield(val) # get new value from caller set(key, val, .merge(:cas => ver)) end |
#connect ⇒ Object Also known as: reconnect
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/couchbase/bucket.rb', line 187 def connect uris = begin builder = CouchbaseConnectionFactoryBuilder.new builder.setTranscoder(transcoder) connection_factory = builder.buildCouchbaseConnection(uris, bucket.to_java_string, password.to_java_string) @client = CouchbaseClient.new(connection_factory) @connected = true rescue Java::ComCouchbaseClientVbucket::ConfigurationException => e fail Couchbase::Error::Auth, "Couchbase configurations are incorrect: #{e.to_s}" rescue java.net.ConnectException => e fail Couchbase::Error::Connect, e.to_s end self end |
#connected? ⇒ Boolean
218 219 220 |
# File 'lib/couchbase/bucket.rb', line 218 def connected? @connected end |
#disconnect ⇒ Object
222 223 224 225 226 227 228 229 230 |
# File 'lib/couchbase/bucket.rb', line 222 def disconnect if connected? && @client.shutdown(3, TimeUnit::SECONDS) @client = nil @connection_factory = nil @connected = false else fail Couchbase::Error::Connect end end |
#flush {|ret| ... } ⇒ true
Delete contents of the bucket
336 337 338 |
# File 'lib/couchbase/bucket.rb', line 336 def flush async_flush.get end |
#host ⇒ Object
183 184 185 |
# File 'lib/couchbase/bucket.rb', line 183 def host hostname end |
#on_connect(&block) ⇒ Object
236 237 238 |
# File 'lib/couchbase/bucket.rb', line 236 def on_connect(&block) @on_connect = block end |
#on_error(&block) ⇒ Object
240 241 242 |
# File 'lib/couchbase/bucket.rb', line 240 def on_error(&block) @on_error = block end |
#quiet? ⇒ Boolean
179 180 181 |
# File 'lib/couchbase/bucket.rb', line 179 def quiet? !!quiet end |
#url ⇒ Object
214 215 216 |
# File 'lib/couchbase/bucket.rb', line 214 def url "http://#{authority}/pools/#{pool}/buckets/#{bucket}/" end |
#version ⇒ Object
244 245 246 247 248 249 250 |
# File 'lib/couchbase/bucket.rb', line 244 def version {}.tap do |hash| @client.getVersions.to_hash.each_pair do |ip, ver| hash[ip.to_s] = ver end end end |