From 23d5f55d2843b51fa3f1da92fef6a72f444d527d Mon Sep 17 00:00:00 2001 From: gahr Date: Mon, 16 Apr 2018 14:39:19 +0000 Subject: [PATCH] Implement, document, and test the ?async and ?keepCache commands Issue #10 --- README.md | 8 ++++++++ doc/retcl.man | 9 +++++++++ retcl.tm | 14 ++++++++++++++ test/013-query-state.test | 23 +++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 test/013-query-state.test diff --git a/README.md b/README.md index 188d86b..dbe98f6 100644 --- a/README.md +++ b/README.md @@ -386,12 +386,20 @@ Either remove the result of the command identified by ***command identifier*** Switch on or off keeping results in the cache after the client has retrieven them using the `result` method. By default, the results cache is enabled. + r ?keepCache + +Query the current setting of `keepCache`. + r +async r -async Switch on or off the asynchronous operation mode. By default, asynchronous operation is enabled. + r ?async + +Query the current setting of `async`. + r pipeline script Execute `script` in the caller scope while holding a Redis pipeline. All Redis diff --git a/doc/retcl.man b/doc/retcl.man index 017d8c5..ad28b60 100644 --- a/doc/retcl.man +++ b/doc/retcl.man @@ -146,6 +146,10 @@ Turn on the use of the [emph {results cache}]. This is the default. Turn off the use of the [emph {results cache}]. Results are removed from the cache as soon as they are retrieved. +[call [emph r] [cmd ?keepCache]] + +Return a boolean value indicating whether cache keeping is currently on or off. + [call [emph r] [cmd clearResult] [opt cmdId]] Remove the result for [opt cmdId] from the [emph {results cache}] or clear it @@ -161,6 +165,11 @@ a [emph {command identifier}]. Turn off asynchronous operation. In this mode, commands wait until a response is received and return the body. +[call [emph r] [cmd ?async]] + +Return a boolean value indicating whether asynchronous operation is currenty on +of off. + [call [emph r] [cmd errorHandler] [opt cmdPrefix]] Set up an [emph {error handler}] to be called whenever an asynchronous error diff --git a/retcl.tm b/retcl.tm index 082a6d2..5ceb407 100644 --- a/retcl.tm +++ b/retcl.tm @@ -239,6 +239,13 @@ oo::class create retcl { } export -async + ## + # Query the currenct asynchronous operation mode. + method ?async {} { + set async + } + export ?async + ## # Turn on keeping results in the cache. method +keepCache {} { @@ -253,6 +260,13 @@ oo::class create retcl { } export -keepCache + ## + # Query the current cache keeping mode. + method ?keepCache {} { + set keepCache + } + export ?keepCache + ## # Setup and error callback or restore the default one ([error]). The # cmdPrefix is passed an additional argument containing the error message. diff --git a/test/013-query-state.test b/test/013-query-state.test new file mode 100644 index 0000000..7486dd4 --- /dev/null +++ b/test/013-query-state.test @@ -0,0 +1,23 @@ +# vim: ft=tcl ts=4 sw=4 expandtab: + +tcltest::loadTestedCommands + +tcltest::test query-state-1.2 {query default asynchronous state} -setup { + set r [retcl new] +} -body { + $r ?async +} -result {1} + +tcltest::test query-state-1.2 {query false asynchronous state} -setup { + set r [retcl new] +} -body { + $r -async + $r ?async +} -result {0} + +tcltest::test query-state-1.3 {query true asynchronous state} -setup { + set r [retcl new] +} -body { + $r +async + $r ?async +} -result {1}