summaryrefslogtreecommitdiff
path: root/src/wasp-db.el
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasp-db.el')
-rw-r--r--src/wasp-db.el21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/wasp-db.el b/src/wasp-db.el
index 2242d907..0311860b 100644
--- a/src/wasp-db.el
+++ b/src/wasp-db.el
@@ -130,6 +130,12 @@ If not, return nil."
(w/db-cmd `("KEYS" ,pat) k)
(error "Redis pattern must be string")))
+(defun w/db-exists (key k)
+ "Query whether KEY exists in Redis and pass the result to K."
+ (if (stringp key)
+ (w/db-cmd `("EXISTS" ,key) (lambda (res) (funcall k (= res 1))))
+ (error "Redis key must be a string")))
+
(defun w/db-set (key val)
"Set KEY to VAL in Redis."
(if (and (stringp key) (stringp val))
@@ -185,16 +191,23 @@ Afterward call K."
(w/db-cmd `("SADD" ,key ,@vals) (lambda (_) nil))
(error "Redis key must be a string")))
+(defun w/db-srem (key &rest vals)
+ "Remove VALS from the set at KEY in Redis."
+ (if (stringp key)
+ (w/db-cmd `("SREM" ,key ,@vals) (lambda (_) nil))
+ (error "Redis key must be a string")))
+
(defun w/db-smembers (key k)
"Pass the members of the set at KEY to K."
(if (stringp key)
(w/db-cmd `("SMEMBERS" ,key) k)
(error "Redis key must be a string")))
-(defun w/db-exists (key k)
- "Query whether KEY exists in Redis and pass the result to K."
- (if (stringp key)
- (w/db-cmd `("EXISTS" ,key) (lambda (res) (funcall k (= res 1))))
+(defun w/db-zadd (key score member &rest others)
+ "Add MEMBER to the sorted set KEY with SCORE.
+Also add any OTHERS."
+ (if (and (stringp key) (stringp score) (stringp member) (-all? #'stringp others))
+ (w/db-cmd `("ZADD" ,key ,score ,member ,@others) (lambda (_) nil))
(error "Redis key must be a string")))
(defun w/db-test ()