GithubHelp home page GithubHelp logo

Comments (5)

cablehead avatar cablehead commented on May 29, 2024

Hi 😄

I think the way to go is to first expose all of the available features Consul offers, with a Ruby centric API and then layer additional, more convenient APIs on top of that.

For python-consul, the approach I've taken is to return all the available JSON for calls that return JSON, and for X-Consul-Index, to return a tuple of (index, data) from all calls that support blocking reads.

e.g. kv.get returns:

    (index, {
        "CreateIndex": 100,
        "ModifyIndex": 200,
        "LockIndex": 200,
        "Key": "foo",
        "Flags": 0,
        "Value": "bar",
        "Session": "adf4238a-882b-9ddc-4a9d-5b6758e4159e"
    })

Returning a tuple is pretty Pythonic. I'm not sure what a more Ruby centric way would be?

This is a little verbose. e.g.

    index, data = c.kv.get('foo')
   # make use of data['Value']

Isn't nearly as nice as:

foo = Diplomat.get('foo')
# => "bar"

if all you want is a KV store. But it does allow you to use all of Consul's features. Particularly long polling to dynamically listen for updates, and it makes ModifyIndex available for cas updates.

Once the API is in place to expose the raw Consul features, additional more convenient APIs like Diplomat's current API can be layered on top.

from diplomat.

galthaus avatar galthaus commented on May 29, 2024

How about this?

Get signature:
get(key, scope=:first, options={})
Input:
options[:index] = string
options[:wait] = string time component
Return
options[:index] is modified on return to be the returned index.

This keeps get happy, doesn't change too much code, gives access to all values over time. The options seems to be the ruby-ish standard way to pass in info and deal with expansion. We could move in scope, but that would break existing things.

If you don't like the writing into an input focused structure, we could add a meta hash to return the requests meta data. Put index, last-contact, ...

I working on this now. I don't really care which I just need long polling. :-)

from diplomat.

johnhamelink avatar johnhamelink commented on May 29, 2024

@galthaus looks nice 👍

Looking forward to seeing that PR!

from diplomat.

johnhamelink avatar johnhamelink commented on May 29, 2024

Solved thanks to #11

from diplomat.

johnhamelink avatar johnhamelink commented on May 29, 2024

Released in version 0.2.2: https://rubygems.org/gems/diplomat/versions/0.2.2

from diplomat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.