Problem using redis-clojure with Leiningen

Hey, I'm new to Clojure and Leiningen and am a bit stuck. I managed to set up a project with Leiningen. I can compile it in uberjar and run repl . I also managed to load a dependency named aleph to run a simple parallel web server.

The next step for me is to use redis-clojure to access redis. But here I am stuck. This is my 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"]]) 

And here is my core.clj : Notice that I added the line (:requre redis) according to the example from 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})) 

When I try to run lein repl , this happens:

 java.io.FileNotFoundException: Could not locate redis__init.class or redis.clj on classpath: (core.clj:1) 

Yes, I ran lein deps , and the redis-clojure banner is available in my lib directory. I probably missed something trivial, but now I have been working on this issue for several hours and am not getting closer to the solution. Thanks!

+4
source share
2 answers

The redis namespace does not exist. I suppose you need

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

Method for checking available namespaces:

 (use 'clojure.contrib.find-namespaces) (filter #(.startsWith (str %) "redis") (find-namespaces-on-classpath)) 
+9
source

This works with more modern versions of Clojure, in this example it finds the names of all namespaces that contain the substring "jdbc":

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

The result is a sequence, for example:

  => 
 ("clojure.java.jdbc") 
+1
source

All Articles