newlisp-redis / test-redis.lsp

#! /usr/bin/newlisp

(define-macro (assert expr)
    (let ((assertion-string (join (list "Assertion failed: " (string expr)) "")))
        (unless (true? (eval expr)) (throw-error assertion-string))))

(define-macro (assert-equals expr val)
  (letex ((e (eval expr)))
    (assert (= e val))))

(define-macro (assert-fail expr)
    (if (nil? (catch (eval expr) 'exc))
      true ; it failed, just what we wanted
      (throw-error (append "Should have failed: " (string expr)))))

(load "redis.lsp")
(setf conn (redis))

(if (nil? conn)
  (throw-error "Could not connect to Redis!")

(assert-equals (:select conn 14) "OK")

;; If you have authentication enabled
;; uncomment this
;; (assert-equals (:auth conn "foobared") "OK")

(assert-equals (:ping conn) "PONG")
(assert-equals (:bgsave conn) "Background saving started")

(println "Database size is " (:dbsize conn))

(println "Keys are " (:keys conn "*"))

(println "Set abcd to 42 => " (:set conn "abcd" 42))
(println "INCR abcd => " (:incr conn "abcd"))
(println "INCRBY 5 => " (:incrby conn "abcd" 5))

(dolist (x (:keys conn "*"))
  (println x " --> " (:get conn x)))

(:close conn)

;(assert-fail (:get conn "minestrone:playlist:sXLruRrkPApP3eErshhqtE"))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.