diff --git a/README.markdown b/README.markdown index 731c3a2..f567a1d 100644 --- a/README.markdown +++ b/README.markdown @@ -290,3 +290,31 @@ JSON socket connected! JSON received: {"SET":[true,"OK"]} JSON received: {"GET":"world"} + +# Pub/Sub with chunked transfer encoding +Webdis exposes Redis PUB/SUB channels to HTTP clients, forwarding messages in the channel as they are published by Redis. This is done using chunked transfer encoding. + +**Example using XMLHttpRequest**: +
+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); + } +}; ++ +Publish messages to redis to see output similar to the following: +
+{"SUBSCRIBE":["subscribe","hello",1]} +{"SUBSCRIBE":["message","hello","\ No newline at end of file"]} +{"SUBSCRIBE":["message","hello"," "]} +