From 692fe51728bb98ac8233b0a6fe654ca433344fb2 Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Fri, 3 Apr 2026 11:37:12 +0200 Subject: [PATCH] update docs --- docs/RESP.html | 19 +++++++++++++++++++ docs/Redis.html | 12 ++++++++++-- docs/redis_index.html | 41 ----------------------------------------- gendocs.carp | 27 +++++++++++++++++++++++++-- redis.carp | 35 +++++++++++++++++++++++++++++++++-- 5 files changed, 87 insertions(+), 47 deletions(-) delete mode 100644 docs/redis_index.html diff --git a/docs/RESP.html b/docs/RESP.html index 4b98d24..d36cb83 100644 --- a/docs/RESP.html +++ b/docs/RESP.html @@ -40,6 +40,25 @@ Protocol. You can create all types, stringify the built types into strings using str, and decode from the string protocol using from-string. Arrays are fully supported, including nested arrays.

+
; 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))
+

If you want your types to be supported when encoding, you’ll have to implement the interface to-redis, the signature of which is (Fn [a] RESP)).

diff --git a/docs/Redis.html b/docs/Redis.html index 0aaeab4..a081668 100644 --- a/docs/Redis.html +++ b/docs/Redis.html @@ -38,8 +38,16 @@

is a wrapper around Redis connections. It supports opening a connection using open or open-on, reading from and sending to the connection (using read and send, -respectively), and contains thin wrappers around all Redis commands (everything -else).

+respectively), and contains thin wrappers around all Redis commands through 7.2.

+
(match (Redis.open "127.0.0.1")
+  (Result.Success r)
+    (do
+      (println* &(Redis.set &r @"key" @"val"))
+      (println* &(Redis.get &r @"key"))
+      (println* &(Redis.lrange &r @"list" @"0" @"-1"))
+      (Redis.close r))
+  (Result.Error err) (IO.errorln &err))
+
diff --git a/docs/redis_index.html b/docs/redis_index.html deleted file mode 100644 index f0b173f..0000000 --- a/docs/redis_index.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - -
- - -
-

- redis -

-

is a Redis client library for Carp.

-
(load "https://git.veitheller.de/carpentry/redis.git@master")
-
- -
- -
- - diff --git a/gendocs.carp b/gendocs.carp index 185208e..ab199ee 100644 --- a/gendocs.carp +++ b/gendocs.carp @@ -5,10 +5,33 @@ (Project.config "docs-logo" "") (Project.config "docs-url" "https://git.veitheller.de/carpentry/redis") (Project.config "docs-styling" "../style.css") -(Project.config "docs-prelude" "is a Redis client library for Carp. +(Project.config "docs-prelude" "is a Redis client library for Carp, supporting Redis 7.x. + +## Installation ``` -(load \"https://git.veitheller.de/carpentry/redis.git@master\") +(load \"https://git.veitheller.de/carpentry/redis.git@0.1.0\") +``` + +## Example + +``` +(defn main [] + (match (Redis.open \"127.0.0.1\") + (Result.Success r) + (do + (println* &(Redis.set &r @\"key\" @\"value\")) + (println* &(Redis.get &r @\"key\")) + (println* &(Redis.lrange &r @\"mylist\" @\"0\" @\"-1\")) + (match (Redis.get &r @\"key\") + (Result.Success resp) + (match resp + (RESP.Str s) (println* \"got: \" &s) + (RESP.Null) (println* \"not found\") + _ (println* \"unexpected type\")) + (Result.Error e) (println* \"error: \" &e)) + (Redis.close r)) + (Result.Error err) (IO.errorln &err))) ``` ") diff --git a/redis.carp b/redis.carp index a190fa4..862e599 100644 --- a/redis.carp +++ b/redis.carp @@ -503,13 +503,44 @@ It takes the same arguments as the [Redis command](https://redis.io/commands/" (doc Redis "is a wrapper around Redis connections. It supports opening a connection using [`open`](#open) or [`open-on`](#open-on), reading from and sending to the connection (using [`read`](#read) and [`send`](#send), -respectively), and contains thin wrappers around all Redis commands (everything -else).") +respectively), and contains thin wrappers around all Redis commands through 7.2. + +``` +(match (Redis.open \"127.0.0.1\") + (Result.Success r) + (do + (println* &(Redis.set &r @\"key\" @\"val\")) + (println* &(Redis.get &r @\"key\")) + (println* &(Redis.lrange &r @\"list\" @\"0\" @\"-1\")) + (Redis.close r)) + (Result.Error err) (IO.errorln &err)) +```") (doc RESP "is a wrapper around the [Redis Serialization Protocol](https://redis.io/topics/protocol). You can create all types, stringify the built types into strings using [`str`](#str), and decode from the string protocol using [`from-string`](#from-string). Arrays are fully supported, including nested arrays. +``` +; 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)) +``` + If you want your types to be supported when encoding, you’ll have to implement the interface `to-redis`, the signature of which is `(Fn [a] RESP))`.")