clojure redis 使用-carmine


現在clojure連接 redis的工具有redis-clojureclj-redis based on JedisAccession, and (the newest) labs-redis-clojure.

但是在我看來carmine文檔比較豐富,所以使用他,https://github.com/ptaoussanis/carmine


現在project.clj中 添加

[com.taoensso/carmine "2.4.5"]
(需要有lein安裝)


在自己的clj文件中添加

(ns my-app (:require [taoensso.carmine :as car :refer (wcar)])) 

定義庫

(def server1-conn {:pool {<opts>} :spec {<opts>}}) 

這裏可以讓我找了半天的地方,在他的api文檔中找到,他需要配置的格式可以參考下面

`conn` arg is a map with connection pool and spec options:
  {:pool {} :spec {:host "127.0.0.1" :port 6379}} ; Default
  {:pool {} :spec {:uri "redis://redistogo:[email protected]:9475/"}}
  {:pool {} :spec {:host "127.0.0.1" :port 6379
                   :password "secret"
                   :timeout-ms 6000
                   :db 3}}

A `nil` or `{}` `conn` or opts will use defaults. A `:none` pool can be used
to skip connection pooling. For other pool options, Ref. http://goo.gl/EiTbn.

定義使用宏

(defmacro wcar* [& body] `(car/wcar server1-conn ~@body))


測試

(wcar* (car/ping)
       (car/set "foo" "bar")
       (car/get "foo"))


再標註下一般我在java中的hget使用格式也記錄下

(wcar* (car/hget "bid" "91801"))




ok,完工。





發佈了56 篇原創文章 · 獲贊 17 · 訪問量 43萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章