aboutsummaryrefslogtreecommitdiff
path: root/README.redis
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2023-02-06 15:55:56 +1000
committerSteve Bennett <steveb@workware.net.au>2023-02-13 10:44:10 +1000
commitaa18a0d938ca171fcf96616cb7ff011034eb5902 (patch)
tree77861adb8abf52a18b23420b9f813995b71ed850 /README.redis
parenta5ea6b096e9e9f9913ad860a847e3757580dd9e4 (diff)
downloadjimtcl-aa18a0d938ca171fcf96616cb7ff011034eb5902.zip
jimtcl-aa18a0d938ca171fcf96616cb7ff011034eb5902.tar.gz
jimtcl-aa18a0d938ca171fcf96616cb7ff011034eb5902.tar.bz2
redis: Add -async support
Supports communication with redis as part of an event loop Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'README.redis')
-rw-r--r--README.redis30
1 files changed, 30 insertions, 0 deletions
diff --git a/README.redis b/README.redis
index 59fc860..1b66eda 100644
--- a/README.redis
+++ b/README.redis
@@ -108,6 +108,8 @@ If no message is received, the read command will wait forever.
The message is returned as: message <channel> <text>
+The 'read' subcommand is also used in non-blocking mode. See the section below for more details.
+
The readable subcommand
~~~~~~~~~~~~~~~~~~~~~~~
@@ -133,3 +135,31 @@ The 'close' command is supported to close the connection.
This command is equivalent to deleting the command with:
rename $r ""
+
+Async/Non-blocking support
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+It is possible to connect to redis in non-blocking mode by using the '-async' flag. e.g.
+
+ set r [redis -async [socket stream localhost:6379]]
+
+Now commands will return immediately with an empty result and 'read' in a 'readable' should
+be used to retrieve the result. As a simple example:
+
+ $r readable {
+ set result [$r read]
+ if {$result ne ""} {
+ puts $result
+ incr next
+ }
+ }
+ $r SET x 5
+ vwait next
+ $r INCR x
+ vwait next
+
+Note that if a large result is returned, 'read' may return an empty string, in
+which case further calls to 'readable' are required to return the result.
+
+In general the underlying socket should be put into non-blocking mode ($sock ndelay 1)
+and a while loop should be used to read reponses until and empty result is returned.