nicolasff / webdis

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

PUBLISH/SUBSCRIBE doesn't appear to work #134

Closed lamby closed 1 year ago

lamby commented 7 years ago

Terminal 1:

$ curl -v http://127.0.0.1:7379/SUBSCRIBE/test
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 7379 (#0)
> GET /SUBSCRIBE/test HTTP/1.1
> Host: 127.0.0.1:7379
> User-Agent: curl/7.50.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: Webdis
< Allow: GET,POST,PUT,OPTIONS
< Access-Control-Allow-Methods: GET,POST,PUT,OPTIONS
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: X-Requested-With, Content-Type
< Content-Type: application/json
< Connection: Keep-Alive
< Transfer-Encoding: chunked
< 

Terminal 2:

$ curl http://127.0.0.1:7379/PUBLISH/test/foo                                                                      
{"PUBLISH":1}

There is no change in terminal 1. I was expecting a {"SUBSCRIBE... line. What am I missing?

yafengabc commented 7 years ago

en,it also can't work with jquery in the example,it use XMLHttpRequest and readyStatus = 3 but jquery seems not support it! the example code is:

var previous_response_length = 0 xhr = new XMLHttpRequest() xhr.open("GET", "http://127.0.0.1:7379/SUBSCRIBE/hello", true); xhr.onreadystatechange = checkData; xhr.send(null);

    function checkData() {
            if(xhr.readyState == 3)  {
                    response = xhr.responseText;
                    chunk = response.slice(previous_response_length);
                    previous_response_length = response.length;
                    console.log(chunk);
            }
    };
lamby commented 7 years ago

but jquery seems not support it!

That would appear to be an entirely separate issue.

matti commented 1 year ago

you need to unbuffer the output: with curl its -N

$ curl -N localhost:7379/SUBSCRIBE/testing
{"SUBSCRIBE":["subscribe","testing",1]}

and then

$ curl localhost:7379/PUBLISH/testing/hello
{"PUBLISH":1}

and subscriber will look like this:

$ curl -N localhost:7379/SUBSCRIBE/testing
{"SUBSCRIBE":["subscribe","testing",1]}{"SUBSCRIBE":["message","testing","hello"]}
lamby commented 1 year ago

Ah, neat. :)

matti commented 1 year ago

6 years later :D

lamby commented 1 year ago

I literally can't remember trying out webdis. :laughing:

matti commented 1 year ago

@lamby I know the feeling.

nicolasff commented 1 year ago

Thanks for the curl tip @matti, I'll add this to the docs.