nicolasff / webdis

A Redis HTTP interface with JSON output
https://webd.is
BSD 2-Clause "Simplified" License
2.82k stars 307 forks source link

Add the key name to the response message? #109

Open penguinpowernz opened 9 years ago

penguinpowernz commented 9 years ago

Unless I am missing something in the readme, it seems that there is no way to see in the response the key name that was requested.

In some situations (such as when using websockets) it would be very advantageous to know the key that was requested in, for instance, a GET command. Take the following for example:

var jsonSocket = new WebSocket("ws://127.0.0.1:7379/");

jsonSocket.onopen = function() {
  console.log("JSON socket connected!");
  jsonSocket.send(JSON.stringify(["GET", "usage.cpu"]));
  jsonSocket.send(JSON.stringify(["GET", "usage.ram"]));
  jsonSocket.send(JSON.stringify(["GET", "usage.hdd"]));
};

jsonSocket.onmessage = function(messageEvent) {
  console.log("JSON received:", messageEvent.data);
};

According to the readme this would output:

JSON received: {"GET": "42%"}
JSON received: {"GET": "90%"}
JSON received: {"GET": "65%"}

Which is which?

I inspected the messageEvent object itself, but found nothing that could help me. It would be incredibly helpful to see an output like this:

JSON received: {"GET": "42%", "KEY": "usage.ram"}
JSON received: {"GET": "90%", "KEY": "usage.cpu"}
JSON received: {"GET": "65%", "KEY": "usage.hdd"}

Is there any way to do this currently?

penguinpowernz commented 9 years ago

If I was pointed to the right file to modify I could try doing a pull request. I had a look through the source but couldn't trace the request through.

PhE commented 9 years ago

Websocket requests are serial. So you should always get your answers in the exact order of your calls.

Feel happy if you get your 3 websocket messages ! When I try your example my websocket is closed after the first send.

IMO, Webdis websocket is definitely not stable :-/ There are many issues related to websocket in webdis. By the way, Webdis seems to be the only way to talk to redis from javascript (and websocket the only way to SUBSCRIBE).

Webdis is perfect for HTTP requests but not ready for websocket.

nicolasff commented 9 years ago

Yes, the websocket code is definitely experimental and support is disabled by default. Unfortunately I have little time to work on it these days, but would certainly welcome contributions.

penguinpowernz commented 9 years ago

I created a project in ruby called Rackdis that gives HTTP access to redis (even with Websockets/chunked encoding) but of course it would be much slower and use more RAM than Webdis and requires that you have ruby on your system.

I'm also thinking of making a similar API for nodejs once I get my head around it.

If I could do C or get my head around the Webdis code I would definitely contribute, but alas I am in the same situation as @nicolasff :(