Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem using redis-clojure with Leiningen

Hey, I'm new to Clojure and Leiningen and a bit stuck. I've managed to setup a project with Leiningen. I'm able to compile it into an uberjar and run the repl. I've also managed to load a dependency named aleph to run a simple concurrent webserver.

The next step for me is to use redis-clojure to access redis. But here I'm 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: Note that I only 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 have run lein deps and the redis-clojure jar is available in my lib directory. I'm probably missing something trivial, but I've been at this issue for a few hours now and not getting any closer to a solution. Thanks!

like image 327
Ariejan Avatar asked Jan 22 '23 04:01

Ariejan


2 Answers

Namespace redis does not exist. I suppose you need

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

A way to check for available namespaces:

(use 'clojure.contrib.find-namespaces)
(filter #(.startsWith (str %) "redis") (find-namespaces-on-classpath))
like image 74
Jürgen Hötzel Avatar answered Jan 28 '23 23:01

Jürgen Hötzel


This works with more current versions of Clojure, in this example it finds the names of all namespaces that contains the sub string "jdbc":

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

The result is a sequence, in example:

=> 
("clojure.java.jdbc")
like image 35
luposlip Avatar answered Jan 28 '23 23:01

luposlip