compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (15)

View Page History
h2. Ruby

The {{observe}} method will return false value in case of timeout and positive in case of success.
The {{observe}} method will return Result object describing state of the key for each node containing it in the cluster. This is low-level operation and user is free to use it to query state of the arbitrary keys.

{code:none}
# observe single key and wait for 5 seconds
# until it will be replicated to at least one replica
observe("foo", :cas => 6635827497922002944, :ttl => 5, :replicas => 1)
# returns true or false
conn = Couchbase.bucket
stats = conn.observe("foo")
# for cluster with 1-replica the stats contents will look like:
# [
# observe multiple keys and wait for 5 seconds
# until they have been replicated to at least one replica
observe({"foo" => 6635827497922002944, "bar" => 16213820143098331136},
:ttl => 5, :replicas => 1)
# returns {"foo" => true, "bar" => true}
# #<Couchbase::Result:0x0000000182d718 error=0x0 key="foo" status=:persisted cas=4640963567427715072 from_master=false time_to_persist=0 time_to_replicate=0>,
# #<Couchbase::Result:0x0000000182d588 error=0x0 key="foo" status=:persisted cas=4640963567427715072 from_master=true time_to_persist=0 time_to_replicate=0>
# ]
{code}

As alternative API all mutators (i.e. set/add/replace/append/prepend) should have two new options:

* {{:num_replicas}} --- how many replicas desired to consider mutator successful. as far as the client knows how many replicas configured, it could also raise ArgumentError exception if this option negative or excessive.
* {{:timeout}} --- the timeout for replication. In this case it would be better to raise exception instead of returning falsy value

The operation supports multiple keys (and will try do distribute them in packets efficiently)
{code:none}
set("foo", "bar", :num_replicas => 2, :timeout => 5)
conn = Couchbase.bucket
stats = conn.observe(["foo", "bar"]) # it splats the arguments, so brackets could be omitted
# again the command executed against 1-replica cluster
# {
# "foo"=>
# [
# #<Couchbase::Result:0x0000000184de50 error=0x0 key="foo" status=:persisted cas=4640963567427715072 from_master=true time_to_persist=57 time_to_replicate=0>,
# #<Couchbase::Result:0x0000000184dc98 error=0x0 key="foo" status=:persisted cas=4640963567427715072 from_master=false time_to_persist=99 time_to_replicate=0>
# ],
# "bar"=>
# [
# #<Couchbase::Result:0x0000000184dd60 error=0x0 key="bar" status=:persisted cas=13536425208630804480 from_master=false time_to_persist=57 time_to_replicate=0>,
# #<Couchbase::Result:0x0000000184dbd0 error=0x0 key="bar" status=:persisted cas=13536425208630804480 from_master=true time_to_persist=99 time_to_replicate=0>
# ]
# }
{code}

Or even better to combine these options into single option {{:observe}}. It will make more clear the fact of addition operation applied here.
The more high level API is available for all mutators (i.e. set/add/replace/append/prepend). User could specify {{:observe}} option with combination of the following keys:

* {{:persisted}} --- the number of nodes desired to persist the key
* {{:replicated}} --- the number of nodes desired to replicate the key (optionally persisted)
* {{:timeout}} --- the timeout for observe.

{code:none}
conn.set("foo", "bar", :observe => {:replicas {:persisted => 2, :timeout => 5})
{code}