patch for redis egg: pubsub support & others

Rolando Abarca via Chicken-users <[email protected]>
Newsgroups gmane.lisp.scheme.chicken
Message-ID <CADnrc4A8DxFfS2rb3ApbdfmHifKhgsQzh0Ve5kOa+-BmKePzYQ@mail.gmail.com>
I'm trying to reach Daniel Ziltener, I have a small patch for his redis egg
(attached). I exported redis-read-reply to be able to use that within a
subscribe command, I also added support for negative (null) arrays, might
not be the best way but it works for my simple case: it returns empty array
instead of null. Finally, I also added support for push-style arrays
(they're semantically the same as regular arrays, except with a ">"
sentinel).

I'm sending this patch here to the list because I could not find a way to
make a PR in his forgejo instance.

Thanks!
Rolando
redis-pubsub.patch (application/octet-stream, 8.8 KB)
From f1ca929d4b3940e5e5e1fef7c963270c114f38f5 Mon Sep 17 00:00:00 2001
From: Rolando Abarca <[email protected]>
Date: Thu, 18 Sep 2025 16:51:52 -0700
Subject: [PATCH 1/4] fixes negative arrays and exports redis-read-reply to
 support pubsub

---
 redis-impl.scm     |  4 ++--
 redis.org          | 39 +++++++++++++++++++++------------------
 redis.release-info |  1 +
 redis.scm          |  2 ++
 4 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/redis-impl.scm b/redis-impl.scm
index 7feeb9b..e21527e 100644
--- a/redis-impl.scm
+++ b/redis-impl.scm
@@ -197,8 +197,8 @@
 ;; [[file:redis.org::read-redis-array][read-redis-array]]
 (define (read-redis-array #!optional port)
   (let* ((port (or port (current-input-port)))
-         (elems (string->number (read-line port)))
-         (vec (make-vector elems)))
+         (elems (max 0 (string->number (read-line port))))
+         (vec (make-vector elems '())))
     (generator-for-each
      (lambda (i)
        (vector-set! vec i (redis-read-reply port)))
diff --git a/redis.org b/redis.org
index 9295e61..db40d00 100644
--- a/redis.org
+++ b/redis.org
@@ -54,25 +54,27 @@
 * API
 
 #+begin_src scheme :noweb yes :tangle redis.scm :exports none
-(define-library (redis)
-  (import (chicken base))
-  (export redis-connect
-          redis-disconnect
-          redis-run
-          redis-run-proc
+  (define-library (redis)
+    (import (chicken base))
+    (export redis-connect
+            redis-disconnect
+            redis-run
+            redis-run-proc
+  	  redis-read-reply ;; used in pub-sub
 
-          make-redis-connection
-          redis-connection?
-          redis-connection-input
-          redis-connection-output
+            make-redis-connection
+            redis-connection?
+            redis-connection-input
+            redis-connection-output
 
-          &redis-error
-          redis-error?
-          redis-error-message
 
-          redis-set-comparator)
-  (begin
-    (include-relative "redis-impl.scm")))
+            &redis-error
+            redis-error?
+            redis-error-message
+
+            redis-set-comparator)
+    (begin
+      (include-relative "redis-impl.scm")))
 #+end_src
 
 #+begin_src scheme :noweb yes :tangle redis-impl.scm :exports none
@@ -414,8 +416,8 @@ Arrays are marked with ~*~ followed by the number of entries, and get returned a
 #+begin_src scheme :tangle redis-impl.scm :exports none
   (define (read-redis-array #!optional port)
     (let* ((port (or port (current-input-port)))
-           (elems (string->number (read-line port)))
-           (vec (make-vector elems)))
+           (elems (max 0 (string->number (read-line port))))
+           (vec (make-vector elems '())))
       (generator-for-each
        (lambda (i)
          (vector-set! vec i (redis-read-reply port)))
@@ -583,6 +585,7 @@ Daniel Ziltener
 | 0.7 | Port to Chicken 6 |
 
 #+name: version-history
+| 0.7 | Bug fixes                       |
 | 0.6 | Easier Protocol Version Setting |
 | 0.5 | Initial Release                 |
 
diff --git a/redis.release-info b/redis.release-info
index 3a29d39..0fdb03a 100644
--- a/redis.release-info
+++ b/redis.release-info
@@ -2,6 +2,7 @@
 ;; -*- Scheme -*-
 (repo git "https://forgejo.lyrion.ch/Chicken/redis.git")
 (uri targz "https://forgejo.lyrion.ch/Chicken/redis/archive/{egg-release}.tar.gz")
+(release "0.7") ;; Bug fixes
 (release "0.6") ;; Easier Protocol Version Setting
 (release "0.5") ;; Initial Release
 ;; Version History:4 ends here
diff --git a/redis.scm b/redis.scm
index d3476aa..e55c6d0 100644
--- a/redis.scm
+++ b/redis.scm
@@ -8,12 +8,14 @@
           redis-disconnect
           redis-run
           redis-run-proc
+	  redis-read-reply ;; used in pub-sub
 
           make-redis-connection
           redis-connection?
           redis-connection-input
           redis-connection-output
 
+
           &redis-error
           redis-error?
           redis-error-message
-- 
2.51.0


From d4be6614db1bc747c612e6b5ad7270a85c957e12 Mon Sep 17 00:00:00 2001
From: Rolando Abarca <[email protected]>
Date: Sun, 16 Nov 2025 18:59:46 -0800
Subject: [PATCH 2/4] adds support for RESP3 push-style arrays

---
 redis-impl.scm | 1 +
 redis.org      | 1 +
 2 files changed, 2 insertions(+)

diff --git a/redis-impl.scm b/redis-impl.scm
index e21527e..54a5cde 100644
--- a/redis-impl.scm
+++ b/redis-impl.scm
@@ -99,6 +99,7 @@
       ((#\#) (read-redis-bool port))
       ((#\_) (read-redis-null port))
       ((#\*) (read-redis-array port))
+      ((#\>) (read-redis-array port)) ;; RESP3 push array
       ((#\%) (read-redis-map port))
       ((#\~) (read-redis-set port))
       ((#\|) (read-redis-with-attributes port)))))
diff --git a/redis.org b/redis.org
index db40d00..1b0af6b 100644
--- a/redis.org
+++ b/redis.org
@@ -190,6 +190,7 @@ This Redis client supports all data types up to and including as specified in [[
         ((#\#) (read-redis-bool port))
         ((#\_) (read-redis-null port))
         ((#\*) (read-redis-array port))
+        ((#\>) (read-redis-array port)) ;; RESP3 push array
         ((#\%) (read-redis-map port))
         ((#\~) (read-redis-set port))
         ((#\|) (read-redis-with-attributes port)))))
-- 
2.51.0


From 2998162a1915c6bdece9cd67952a7dbecc63c751 Mon Sep 17 00:00:00 2001
From: Rolando Abarca <[email protected]>
Date: Mon, 17 Nov 2025 15:57:26 -0800
Subject: [PATCH 3/4] whitespace fix

---
 redis.org | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/redis.org b/redis.org
index 1b0af6b..485261c 100644
--- a/redis.org
+++ b/redis.org
@@ -60,7 +60,7 @@
             redis-disconnect
             redis-run
             redis-run-proc
-  	  redis-read-reply ;; used in pub-sub
+            redis-read-reply ;; used in pub-sub
 
             make-redis-connection
             redis-connection?
-- 
2.51.0


From 4272f3a747fadb06759ca8c7687bb7d42955293a Mon Sep 17 00:00:00 2001
From: Rolando Abarca <[email protected]>
Date: Mon, 17 Nov 2025 16:03:48 -0800
Subject: [PATCH 4/4] cleanup version & tables

---
 redis.egg            | 2 +-
 redis.org            | 7 ++-----
 redis.release-info   | 2 +-
 redis.release-info.6 | 1 +
 redis.scm            | 6 +-----
 5 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/redis.egg b/redis.egg
index d321363..e5ad6d0 100644
--- a/redis.egg
+++ b/redis.egg
@@ -7,7 +7,7 @@
  (synopsis "A Redis client library for Chicken Scheme")
  (category db)
  (license "BSD")
- (version "0.7")
+ (version "0.8")
  (dependencies srfi-34 srfi-35 srfi-69 srfi-113 srfi-128 srfi-152 srfi-158)
  (test-dependencies test)
 
diff --git a/redis.org b/redis.org
index 485261c..1d5f576 100644
--- a/redis.org
+++ b/redis.org
@@ -61,17 +61,13 @@
             redis-run
             redis-run-proc
             redis-read-reply ;; used in pub-sub
-
             make-redis-connection
             redis-connection?
             redis-connection-input
             redis-connection-output
-
-
             &redis-error
             redis-error?
             redis-error-message
-
             redis-set-comparator)
     (begin
       (include-relative "redis-impl.scm")))
@@ -583,10 +579,11 @@ Daniel Ziltener
 ** Version History
 
 #+name: version-history-6
+| 0.8 | Support PUBSUB    |
 | 0.7 | Port to Chicken 6 |
 
 #+name: version-history
-| 0.7 | Bug fixes                       |
+| 0.8 | Support PUBSUB                  |
 | 0.6 | Easier Protocol Version Setting |
 | 0.5 | Initial Release                 |
 
diff --git a/redis.release-info b/redis.release-info
index 0fdb03a..792434b 100644
--- a/redis.release-info
+++ b/redis.release-info
@@ -2,7 +2,7 @@
 ;; -*- Scheme -*-
 (repo git "https://forgejo.lyrion.ch/Chicken/redis.git")
 (uri targz "https://forgejo.lyrion.ch/Chicken/redis/archive/{egg-release}.tar.gz")
-(release "0.7") ;; Bug fixes
+(release "0.8") ;; Support PUBSUB
 (release "0.6") ;; Easier Protocol Version Setting
 (release "0.5") ;; Initial Release
 ;; Version History:4 ends here
diff --git a/redis.release-info.6 b/redis.release-info.6
index cdb0bc4..92547c9 100644
--- a/redis.release-info.6
+++ b/redis.release-info.6
@@ -2,5 +2,6 @@
 ;; -*- Scheme -*-
 (repo git "https://forgejo.lyrion.ch/Chicken/redis.git")
 (uri targz "https://forgejo.lyrion.ch/Chicken/redis/archive/{egg-release}.tar.gz")
+(release "0.8") ;; Support PUBSUB
 (release "0.7") ;; Port to Chicken 6
 ;; Version History:3 ends here
diff --git a/redis.scm b/redis.scm
index e55c6d0..728ad73 100644
--- a/redis.scm
+++ b/redis.scm
@@ -8,18 +8,14 @@
           redis-disconnect
           redis-run
           redis-run-proc
-	  redis-read-reply ;; used in pub-sub
-
+          redis-read-reply ;; used in pub-sub
           make-redis-connection
           redis-connection?
           redis-connection-input
           redis-connection-output
-
-
           &redis-error
           redis-error?
           redis-error-message
-
           redis-set-comparator)
   (begin
     (include-relative "redis-impl.scm")))
-- 
2.51.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.