嘿,我是 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
:请注意,我只根据 redis-clojure 中的示例添加了行 (:requre redis)
。
(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
并且我的 lib
目录中提供了 redis-clojure jar。我可能遗漏了一些微不足道的东西,但我已经在这个问题上待了几个小时了,并没有接近解决方案。谢谢!
最佳答案
命名空间 redis 不存在。我想你需要
(:require [redis.core :as redis])
一种检查可用命名空间的方法:
(use 'clojure.contrib.find-namespaces)
(filter #(.startsWith (str %) "redis") (find-namespaces-on-classpath))
关于clojure - 在 Leiningen 中使用 redis-clojure 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4079220/