使用Leiningen使用Redis-Clojure的问题
题
嘿,我是Clojure和Leiningen的新手,有点困扰。我已经设法与Leiningen设置了一个项目。我能够将其编译成Uberjar并运行 repl
. 。我还设法加载了一个名为的依赖项 aleph
运行一个简单的并发网络服务器。
对我的下一步是使用 redis-clojure
访问Redis。但是我在这里被困。这是我的 project.clj
:
(defproject alpha "0.0.1-SNAPSHOT"
:description "Just an alpha test script"
:main alpha.core
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[aleph, "0.1.2-SNAPSHOT"]
[redis-clojure "1.2.4"]])
这是我的 core.clj
: :请注意,我只添加了行 (:requre redis)
根据Redis-Clojure的示例。
(ns alpha.core
(:require redis)
(:gen-class))
(use `aleph.core 'aleph.http)
(defn alpha [channel request]
(let [] (enqueue-and-close channel
{:status 200
:header {"Content-Type" "text/html"}
:body "Hello Clojure World!"}))
(println (str request)))
(defn -main [& args]
(start-http-server alpha {:port 9292}))
当我尝试运行时 lein repl
有时候是这样的:
java.io.FileNotFoundException: Could not locate redis__init.class or redis.clj on classpath: (core.clj:1)
是的,我跑了 lein deps
我的Redis-clojure罐子里有我的 lib
目录。我可能缺少一些微不足道的东西,但是我已经在这个问题上呆了几个小时,并且没有接近解决方案。谢谢!
解决方案
名称空间 Redis 不存在。我想你需要
(:require [redis.core :as redis])
一种检查可用名称空间的方法:
(use 'clojure.contrib.find-namespaces)
(filter #(.startsWith (str %) "redis") (find-namespaces-on-classpath))
其他提示
这与Clojure的最新版本一起起作用,在此示例中,它找到了包含子字符串“ JDBC”的所有名称空间的名称:
(map str
(filter
#(> (.indexOf (str %) "jdbc") -1)
(all-ns)))
结果是一个序列,例如:
=> ("clojure.java.jdbc")
不隶属于 StackOverflow