Source

newlisp-redis / test-redis.lsp

Full commit
#! /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!")
  true)

(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"))
(exit)