From 7255c5e7df4f7fa21b3188f4d637aceeb969228a Mon Sep 17 00:00:00 2001 From: Luca Pellicoro Date: Fri, 7 Dec 2012 00:26:07 -0800 Subject: [PATCH 1/2] Add javscript chunk encoding example in readme --- README.markdown | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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",""]}
+{"SUBSCRIBE":["message","hello",""]} 
+
\ No newline at end of file From 94b4d80a48b5b16dd84dbd219eb8f6e91ee4395f Mon Sep 17 00:00:00 2001 From: Luca Pellicoro Date: Fri, 7 Dec 2012 00:27:40 -0800 Subject: [PATCH 2/2] Don't interfere with markdown --- README.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index f567a1d..9121325 100644 --- a/README.markdown +++ b/README.markdown @@ -315,6 +315,6 @@ function checkData() { Publish messages to redis to see output similar to the following:
 {"SUBSCRIBE":["subscribe","hello",1]}
-{"SUBSCRIBE":["message","hello",""]}
-{"SUBSCRIBE":["message","hello",""]} 
+{"SUBSCRIBE":["message","hello","some message"]}
+{"SUBSCRIBE":["message","hello","some other message"]} 
 
\ No newline at end of file