Uploaded image for project: 'Couchbase Ruby client library'
  1. Couchbase Ruby client library
  2. RCBC-31

The get command is not idiomatic, a multi-get command should be added to ensure consistent processing of the result

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2.0.z.beta
    • Component/s: None
    • Security Level: Public
    • Labels:
      None

      Description

      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

      No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

        Show
        avsej Sergey Avseyev added a comment - https://github.com/couchbase/couchbase-ruby-client/commit/538aba7534e2255c295565242d1072a0a45482ee
        Hide
        avsej Sergey Avseyev added a comment -
        Show
        avsej Sergey Avseyev added a comment - Updated that patch http://review.couchbase.org/14759
        Hide
        avsej Sergey Avseyev added a comment -

        > get(["foo"], :extended => true) #=>

        { "foo" => [value, 0x001, 12342343433343] }

        Sorry I missed that it is only one member

        Show
        avsej Sergey Avseyev added a comment - > get( ["foo"] , :extended => true) #=> { "foo" => [value, 0x001, 12342343433343] } Sorry I missed that it is only one member
        Hide
        avsej Sergey Avseyev added a comment -

        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.

        Show
        avsej Sergey Avseyev added a comment - 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.
        Hide
        bpoweski Ben Poweski added a comment - - edited

        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] }
        Show
        bpoweski Ben Poweski added a comment - - edited 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] }
        Hide
        avsej Sergey Avseyev added a comment -

        Here is the patch http://review.couchbase.org/14759

        Does it makes sense for you?

        Show
        avsej Sergey Avseyev added a comment - Here is the patch http://review.couchbase.org/14759 Does it makes sense for you?
        Hide
        avsej Sergey Avseyev added a comment -

        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?

        Show
        avsej Sergey Avseyev added a comment - 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?

          People

          • Assignee:
            avsej Sergey Avseyev
            Reporter:
            bpoweski Ben Poweski
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Gerrit Reviews

              There are no open Gerrit changes