update docs
This commit is contained in:
@@ -40,6 +40,25 @@ Protocol</a>. You can create all types,
|
||||
stringify the built types into strings using <a href="#str"><code>str</code></a>, and decode from
|
||||
the string protocol using <a href="#from-string"><code>from-string</code></a>. Arrays are fully
|
||||
supported, including nested arrays.</p>
|
||||
<pre><code>; decoding
|
||||
(RESP.from-string "+OK\r\n") ; => (Success (Str @"OK"))
|
||||
(RESP.from-string ":42\r\n") ; => (Success (Integer 42))
|
||||
(RESP.from-string "$-1\r\n") ; => (Success (Null))
|
||||
|
||||
; encoding
|
||||
(str &(RESP.Str @"hi")) ; => "$2\r\nhi\r\n"
|
||||
(str &(RESP.Integer 42)) ; => ":42\r\n"
|
||||
|
||||
; pattern matching on responses
|
||||
(match (Redis.get &r @"key")
|
||||
(Result.Success resp)
|
||||
(match resp
|
||||
(RESP.Str s) (println* "got: " &s)
|
||||
(RESP.Null) (println* "not found")
|
||||
(RESP.Arr items) (println* "array of " &(Int.str (Array.length &items)))
|
||||
_ (println* "other"))
|
||||
(Result.Error e) (println* "error: " &e))
|
||||
</code></pre>
|
||||
<p>If you want your types to be supported when encoding, you’ll have to implement
|
||||
the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RESP))</code>.</p>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user