代码之家  ›  专栏  ›  技术社区  ›  Ariejan

在Leiningen中使用redis clojure时出现问题

  •  4
  • Ariejan  · 技术社区  · 14 年前

    repl . 我还加载了一个名为 aleph 运行一个简单的并发web服务器。

    对我来说下一步是 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 jar在我的 lib 目录。我可能遗漏了一些琐碎的事情,但我已经在这个问题上讨论了几个小时,没有找到任何解决方案。谢谢!

    2 回复  |  直到 14 年前
        1
  •  8
  •   Jürgen Hötzel    14 年前

    命名空间 redis公司

    (:require [redis.core :as redis])
    

    检查可用名称空间的方法:

    (use 'clojure.contrib.find-namespaces)
    (filter #(.startsWith (str %) "redis") (find-namespaces-on-classpath))
    
        2
  •  1
  •   luposlip    12 年前

    这适用于更新版本的Clojure,在本例中,它将查找包含子字符串“jdbc”的所有命名空间的名称:

    (map str
      (filter
        #(> (.indexOf (str %) "jdbc") -1)
        (all-ns)))
    

    结果是一个序列,例如:

    => 
    ("clojure.java.jdbc")