Module: Couchbase::Operations::Store
- Defined in:
- lib/couchbase/operations/store.rb
Constant Summary collapse
- STORE_OP_METHODS =
{ set: -> client, key, value, ttl, transcoder { client.set(key, ttl, value, transcoder) }, add: -> client, key, value, ttl, transcoder { client.add(key, ttl, value, transcoder) }, replace: -> client, key, value, ttl, transcoder { client.replace(key, ttl, value, transcoder) }, append: -> client, key, value, ttl, transcoder { client.append(key, value) }, prepend: -> client, key, value, ttl, transcoder { client.prepend(key, value) } }.freeze
Instance Method Summary collapse
- #[]=(key, *args) ⇒ Object
-
#add(key, value, options = {}) {|ret| ... } ⇒ Fixnum
Add the item to the database, but fail if the object exists already.
-
#append(key, value, options = {}) ⇒ Fixnum
Append this object to the existing object.
- #async_add(key, value, options, &block) ⇒ Object
- #async_replace(key, value, options, &block) ⇒ Object
- #async_set(key, value, options, &block) ⇒ Object
-
#prepend(key, value, options = {}) ⇒ Object
Prepend this object to the existing object.
-
#replace(key, value, options = {}) ⇒ Fixnum
Replace the existing object in the database.
-
#set(key, value, options = {}) {|ret| ... } ⇒ Fixnum
Unconditionally store the object in the Couchbase.
Instance Method Details
#[]=(key, *args) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/couchbase/operations/store.rb', line 139 def []=(key, *args) = args.size > 1 ? args.shift : {} value = args.pop set(key, value, ) end |
#add(key, value, options = {}) {|ret| ... } ⇒ Fixnum
Add the item to the database, but fail if the object exists already
195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/couchbase/operations/store.rb', line 195 def add(key, value = nil, = {}) if async? if block_given? async_add(key, value, , &Proc.new) else async_add(key, value, ) end else sync_block_error if block_given? store_op(:add, key, value, ) end end |
#append(key, value, options = {}) ⇒ Fixnum
This operation is kind of data-aware from server point of view. This mean that the server treats value as binary stream and just perform concatenation, therefore it won’t work with :marshal
and :document
formats, because of lack of knowledge how to merge values in these formats. See Bucket#cas for workaround.
Append this object to the existing object
343 344 345 346 |
# File 'lib/couchbase/operations/store.rb', line 343 def append(key, value) sync_block_error if block_given? store_op(:append, key, value) end |
#async_add(key, value, options, &block) ⇒ Object
208 209 210 |
# File 'lib/couchbase/operations/store.rb', line 208 def async_add(key, value, , &block) async_store_op(:add, key, value, , &block) end |
#async_replace(key, value, options, &block) ⇒ Object
266 267 268 |
# File 'lib/couchbase/operations/store.rb', line 266 def async_replace(key, value, , &block) async_store_op(:replace, key, value, , &block) end |
#async_set(key, value, options, &block) ⇒ Object
135 136 137 |
# File 'lib/couchbase/operations/store.rb', line 135 def async_set(key, value, , &block) async_store_op(:set, key, value, , &block) end |
#prepend(key, value, options = {}) ⇒ Object
This operation is kind of data-aware from server point of view. This mean that the server treats value as binary stream and just perform concatenation, therefore it won’t work with :marshal
and :document
formats, because of lack of knowledge how to merge values in these formats. See Bucket#cas for workaround.
Prepend this object to the existing object
400 401 402 403 |
# File 'lib/couchbase/operations/store.rb', line 400 def prepend(key, value) sync_block_error if block_given? store_op(:prepend, key, value) end |
#replace(key, value, options = {}) ⇒ Fixnum
Replace the existing object in the database
253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/couchbase/operations/store.rb', line 253 def replace(key, value, = {}) if async? if block_given? async_replace(key, value, , &Proc.new) else async_replace(key, value, ) end else sync_block_error if block_given? store_op(:replace, key, value, ) end end |
#set(key, value, options = {}) {|ret| ... } ⇒ Fixnum
Unconditionally store the object in the Couchbase
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/couchbase/operations/store.rb', line 122 def set(key, value = nil, = {}) if async? if block_given? async_set(key, value, , &Proc.new) else async_set(key, value, ) end else sync_block_error if block_given? store_op(:set, key, value, ) end end |