Module: Couchbase::Operations::Arithmetic
- Defined in:
- lib/couchbase/operations/arithmetic.rb
Instance Method Summary collapse
-
#decr(key, delta = 1, options = {}) {|ret| ... } ⇒ Fixnum
(also: #decrement)
Decrement the value of an existing numeric key.
-
#incr(key, delta = 1, options = {}) {|ret| ... } ⇒ Fixnum
(also: #increment)
Increment the value of an existing numeric key.
Instance Method Details
#decr(key, delta = 1, options = {}) {|ret| ... } ⇒ Fixnum Also known as: decrement
that server values stored and transmitted as unsigned numbers, therefore if you try to decrement negative or zero key, you will always get zero.
Decrement the value of an existing numeric key
The decrement methods reduce the value of a given key if the corresponding value can be parsed to an integer value. These operations are provided at a protocol level to eliminate the need to get, update, and reset a simple integer value in the database. It supports the use of an explicit offset value that will be used to reduce the stored value in the database.
191 192 193 194 |
# File 'lib/couchbase/operations/arithmetic.rb', line 191 def decr(*args) sync_block_error if !async? && block_given? do_arithmetic(:decr, *args) end |
#incr(key, delta = 1, options = {}) {|ret| ... } ⇒ Fixnum Also known as: increment
that server values stored and transmitted as unsigned numbers, therefore if you try to store negative number and then increment or decrement it will cause overflow. (see “Integer overflow” example below)
Increment the value of an existing numeric key
The increment methods allow you to increase a given stored integer value. These are the incremental equivalent of the decrement operations and work on the same basis; updating the value of a key if it can be parsed to an integer. The update operation occurs on the server and is provided at the protocol level. This simplifies what would otherwise be a two-stage get and set operation.
102 103 104 105 |
# File 'lib/couchbase/operations/arithmetic.rb', line 102 def incr(*args) sync_block_error if !async? && block_given? do_arithmetic(:incr, *args) end |