jplana / python-etcd

A python client for etcd
Other
520 stars 210 forks source link

Impossible to insert dict to create data structure #204

Closed bs-sdev closed 7 years ago

bs-sdev commented 7 years ago

Hello everyone,

I Would like insert a dict to create a datastructure, here is an example:

dict_value = {'media': 42, 'min_duration': 0}

client.write("/test", dict_value)

If I take a look on my browser (I could make it via a client.read ....), here is the result:

{

"action": "get",
"node": {
    "key": "/test",
    "value": "{'media': 42, 'min_duration': 0}",
    "modifiedIndex": 12568,
    "createdIndex": 12568
}

}

I would like something like this:

{

"action": "get",
"node": {
    "key": "/test",
    "dir": true,
    "nodes": [
        {
            "key": "/test/media",
            "value": "42",
            "modifiedIndex": 12571,
            "createdIndex": 12571
        },
        {
            "key": "/test/min-duration",
            "value": "0",
            "modifiedIndex": 12572,
            "createdIndex": 12572
        }
    ],
    "modifiedIndex": 12570,
    "createdIndex": 12570
}

}

Does someone have this problem? Did I miss something? Or maybe it is not implemented into the python-etcd client and I should make it via a curl command???

Thanks.

lavagetto commented 7 years ago

@bs-sdev you are trying to do something that is nowhere to be found in our documentation.

you should do something like

  dict_value = {'media': 42, 'min_duration': 0}
  key_prefix = '/test'
  for k, v in dict_value.iteritems():
      key = os.path.join(key_prefix, k)
      client.write(key, v)

there is a good reason why if you tell python-etcd to write a dict to etcd it will do it: that many people (me included) like to store data structures into it.

madcrokodile commented 3 years ago

@lavagetto, hello! Is it possible to make this operation atomic?