Clojure 学习入门(9)—— 连接redis
来源:互联网 发布:搭建卡盟分销源码 编辑:程序博客网 时间:2024/05/21 06:41
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
2 0
- Clojure 学习入门(9)—— 连接redis
- Clojure 学习入门(9)- 连接redis
- Clojure 学习入门(7)—— 连接mysql
- Clojure 学习入门(8)—— 连接mongodb
- Clojure 学习入门(7)- 连接mysql
- Clojure 学习入门(8)- 连接mongodb
- Clojure 学习入门(1)—— 学习资料
- Clojure 学习入门(2)—— eclipse 插件
- Clojure 学习入门(6)—— 函数定义
- Clojure 学习入门(5)—— 关键字
- Clojure 学习入门(3)—— 数字类型
- Clojure 学习入门(4)—— 字符串
- Clojure 学习入门(16)—— 正则表达式
- Clojure 学习入门(15)—— 条件判断
- Clojure 学习入门(17)—— 异常处理
- Clojure 学习入门(14)—— 循环控制
- Clojure 学习入门(13)—— binding
- Clojure 学习入门(10)—— httpkit
- 轻松学C#
- U3d协程
- Oracle 数据库12c新特性总结(四)
- 黑马程序员:单例模式与多线程应用
- jquery.uploadify 3.2 使用
- Clojure 学习入门(9)—— 连接redis
- Mono下载
- register_chrdev_region()系列函数剖析
- plsql连接远程oracle,在本机没有oracle的情况下
- hdu 2035 人见人爱A^B
- 现在IO总线体系架构----PCI-E
- jQuery2.0应用开发:SSH框架整合jQuery2.0实战OA办公自动化(VSS、operamasks-UI框架)
- 处理UnicodeDecodeError: ‘XXX' codec can't decode bytes in position...的问题
- 轻松学C++