clojure 连接 redis 示例
project.cli 添加redis依赖:[clj-redis "0.0.12"]
(defproject myClojure "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [
[org.clojure/clojure "1.5.1"]
[org.clojure/java.jdbc "0.0.6"]
[org.clojure/clojure-contrib "1.2.0"]
[mysql/mysql-connector-java "5.1.26"]
[com.novemberain/monger "1.5.0"]
[com.taoensso/carmine "1.2.1"]
[clj-redis "0.0.12"]
])
示例代码:
(ns myClojure.redis2
(require [clj-redis.client :as redis]))
;; 连接redis
(def db (redis/init))
(println (redis/ping db))
(println (redis/set db "foo" "BAR"))
(println (redis/get db "foo"))
(println) ;; 空一行
(println (redis/set db "blog" "http://blog.ithomer.net"))
(println (redis/get db "blog"))
运行结果:
PONG
OK
BAR
OK
http://blog.ithomer.net
redis 数据内容:
Carmine 示例
Carmine, a Clojure Redis client
project.clj 添加依赖:[com.taoensso/carmine "2.4.0"]
示例代码:
(ns myClojure.redis
(:require [taoensso.carmine :as car]
[taoensso.carmine.message-queue :as carmine-mq])
(:gen-class :main true))
(def pool (car/make-conn-pool)) ; See docstring for additional options
(def spec-server1 (car/make-conn-spec)) ; ''
(defmacro wcar [& body] `(car/with-conn pool spec-server1 ~@body))
(defn -main [& args]
(println "rd01 run!")
;;
(wcar (car/ping)
(car/set "foo" "hello ithomer")
(car/get "foo"))
)
(-main)
运行结果:rd01 run!["PONG" "OK" "hello ithomer"]
参考推荐:
Carmine, a Clojure Redis client(github)
clj-redis(github)
clojure操作redis
分享到:
相关推荐
NULL 博文链接:https://clojure.iteye.com/blog/1741375
NULL 博文链接:https://clojure.iteye.com/blog/1742475
Clojure入门教程
Clojure学习教程.pdf
Clojure入门教程- Clojure – Functional Programming for the JVM中文版
Clojure入门介绍: Clojure - Functional Programming for the JVM
Clojure学习文档,Clojure-Web开发学习,覆盖了Clojure由浅入深的基本学习
本次演讲中,庄晓丹从AVOSCloud这个完全基于Clojure构建的移动云平台出发,分享Avos团队在Clojure上的实践和经验,为国内Clojure的传播贡献一份力量。
celtuce:莴苣的Clojure包装器(Java Redis客户端)
这是Programming Clojure 电子版的 纸质版本在美国亚马逊要到2009年3月才能上架 Paperback: 200 pages Publisher: Pragmatic Bookshelf (March 15, 2009) Language: English ISBN-10: 1934356336 ISBN-13: 978-...
Clojure is an opinionated language—it doesn’t try to cover all paradigms or provide every checklist bullet-point feature. Instead it provides the features needed to solve all kinds of real-world ...
Redis支持多种语言,诸如Ruby,Python, Twisted Python, PHP, Erlang, Tcl, Perl, Lua, Java, Scala, Clojure等。 主-从复制 Redis支持简单而快速的主-从复制。 官方提供了一个数据,Slave在21秒即完成了对Amazon网站...
Clear, practical Clojure for the professional programmer Professional Clojure is the experienced developer's guide to functional programming using the Clojure language. Designed specifically to meet ...
Practical Clojure Clojure语言书籍
Clojure oj 是一个新的 Clojure 库,用来与数据库进行通讯,灵感来自于 Ring. 示例代码: (require [oj.core :as oj]) [oj.modifiers :as db]) (defn find-by-username [username] (-> (db/query ...
clojure clojure clojureclojure clojure
【1】[Clojure编程乐趣](The Joy of Clojure).pdf 【2】Clojure – Functional Programming for the JVM中文版.pdf 【3】Clojure Cookbook.pdf 【4】Clojure Data Analysis Cookbook.pdf 【5】clojure Hand book...
[2013] Functional Programming Patterns in Scala and Clojure - Write Lean Programs for the JVM.(Michael Bevilacqua-Linn).[1937785475].pdf+epub.rar [2014] Clojure Cookbook - Recipes for Functional ...