[RCBC-31] The get command is not idiomatic, a multi-get command should be added to ensure consistent processing of the result Created: 10/Apr/12  Updated: 13/Nov/12  Resolved: 17/Apr/12

Status: Closed
Project: Couchbase Ruby client library
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2.0.z.beta
Security Level: Public

Type: New Feature Priority: Major
Reporter: Ben Poweski Assignee: Sergey Avseyev
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

The pattern of using more than one argument to determine if an array should be returned is not idiomatic. Consider the case of a multi-get in an application where I have n items to return. If there happens to be only one item it will be treated differently than if there happens to be 2 items.

This forces the application user to wrap all results with a check to see if the result is an array or not in every use of the command

Comment by Sergey Avseyev [ 11/Apr/12 ]
Indeed. What if I leave current get implementation, but now will return Array if the keys passed as Array, even if there was single element there:

  get(["foo"]) #=> ["bar"]
  get("foo") #=> "bar"

In this case the method behaviour will be consistent. What do you think?
Comment by Sergey Avseyev [ 11/Apr/12 ]
Here is the patch http://review.couchbase.org/14759

Does it makes sense for you?
Comment by Ben Poweski [ 11/Apr/12 ]
You should consider adding a get_multi option as the the dalli driver uses this pattern.

get_multi("key1", "key2") #=> { "key1" => 1, "key2" => 2 }

Also, our use case is to use the :extended => true option so we may retrieve the integer flag.

I should expect this to work:

get(["foo"], :extended => true) #=> { "foo" => [value, 0x001, 12342343433343] }
Comment by Sergey Avseyev [ 11/Apr/12 ]
The latter case is working actually

  1.9.2p318 (main):011:0> Couchbase.bucket.get("x", "y", :extended => true)
  {"x"=>["xval", 0, 12204754167235346432], "y"=>["yval", 0, 15062578311643791360]}
  1.9.2p318 (main):012:0> Couchbase.bucket.get(["x", "y"], :extended => true)
  {"x"=>["xval", 0, 12204754167235346432], "y"=>["yval", 0, 15062578311643791360]}

In first case I'm returning just array because it has the same order as arguments. So that you can assign them directly to variables:

  x, y = Couchbase.bucket.get(["x", "y"])

and you can easily build a Hash from it

  keys = ["x", "y"]
  vals = Couchbase.bucket.get(keys)
  Hash[keys.zip(vals)] #=> {"x"=>"xval", "y"=>"yval"}

The version with such behaviour already published, I can create wrapper which will do it for you, or add new option.
Comment by Sergey Avseyev [ 11/Apr/12 ]
> get(["foo"], :extended => true) #=> { "foo" => [value, 0x001, 12342343433343] }

Sorry I missed that it is only one member
Comment by Sergey Avseyev [ 11/Apr/12 ]
Updated that patch http://review.couchbase.org/14759
Comment by Sergey Avseyev [ 17/Apr/12 ]
Generated at Sat Jul 12 04:29:19 CDT 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.