taoensso / carmine

Redis client + message queue for Clojure
https://www.taoensso.com/carmine
Eclipse Public License 1.0
1.15k stars 131 forks source link

Request : Simple minimal example - connect - write -read #97

Closed mstram closed 9 years ago

mstram commented 9 years ago

I've spent the last few hours searching github, google, etc for one working example using this library, and have yet to find one !

As a clojure noob, the "snippets" in the readme.md don't really help.

Pullease .......... post one here !

Mike

kenny-evitt commented 9 years ago

Here's something you should be able to type in a REPL:

(require '[taoensso.carmine :as car :refer (wcar)])
(def server-conn nil) ; Connect to the Redis instance on the local host on the default port (6379).
(defmacro wcar* [& body] `(car/wcar server1-conn ~@body))

(wcar*
       (car/ping)
       (car/set "foo" "bar")
       (car/get "foo"))

The car namespace includes a function for every Redis command and they're all named the same and accept the same arguments.

In general, you can just pass Clojure values (e.g. maps, vectors) to those functions and they'll be serialized and de-serialized automagically.

mstram commented 9 years ago

Thanks, but ...

After the first line :

(require '[taoensso.carmine :as car :refer (wcar)])

CompilerException java.io.FileNotFoundException: Could not locate taoensso/encore__init.class or taoensso/encore.clj on classpat h: , compiling:(taoensso/carmine.clj:1:1)

user=> (println (System/getProperty "java.class.path"))

/home/action/clojure/clojure-1.6.0.jar:/home/action/clojure/carmine-2.7.0-RC1.jar:/home/action/clojure/redis-clojure-1.3.2.jar:/ home/action/clojure/jline-1.0.jar:/home/action/clojure/commons-pool-1.5.5.jar

I generated carmine-2.7.0-RC1.jar, by running 'lein uberjar' from the repo main directory

Any ideas ?

Mike

On 8/6/14, kenny-evitt notifications@github.com wrote:

Here's something you should be able to type in a REPL:

(require '[taoensso.carmine :as car :refer (wcar)])
(def server-conn nil) ; Connect to the Redis instance on the local host on
the default port (6379).
(defmacro wcar* [& body] `(car/wcar server1-conn ~@body))

(wcar*
       (car/ping)
       (car/set "foo" "bar")
       (car/get "foo"))

The car namespace includes a function for every Redis command and they're all named the same and accept the same arguments.

In general, you can just pass Clojure values (e.g. maps, vectors) to those functions and they'll be serialized and de-serialized automagically.


Reply to this email directly or view it on GitHub: https://github.com/ptaoussanis/carmine/issues/97#issuecomment-51424458

mstram commented 9 years ago

Not that I'm even getting that far (but hopefully eventually)

Shouldn't 'server1-conn' be 'server-conn' ?

(def server-conn nil) ; Connect to the Redis instance on the local host on the default port (6379).

(defmacro wcar* [& body] `(car/wcar server1-conn ~@body)) ############################## ^^^^^^^^^^^^^^^ ###########

On 8/6/14, mstram . mikestramba@gmail.com wrote:

Thanks, but ...

After the first line :

(require '[taoensso.carmine :as car :refer (wcar)])

CompilerException java.io.FileNotFoundException: Could not locate taoensso/encore__init.class or taoensso/encore.clj on classpat h: , compiling:(taoensso/carmine.clj:1:1)

user=> (println (System/getProperty "java.class.path"))

/home/action/clojure/clojure-1.6.0.jar:/home/action/clojure/carmine-2.7.0-RC1.jar:/home/action/clojure/redis-clojure-1.3.2.jar:/ home/action/clojure/jline-1.0.jar:/home/action/clojure/commons-pool-1.5.5.jar

I generated carmine-2.7.0-RC1.jar, by running 'lein uberjar' from the repo main directory

Any ideas ?

Mike

On 8/6/14, kenny-evitt notifications@github.com wrote:

Here's something you should be able to type in a REPL:

(require '[taoensso.carmine :as car :refer (wcar)])
(def server-conn nil) ; Connect to the Redis instance on the local host
on
the default port (6379).
(defmacro wcar* [& body] `(car/wcar server1-conn ~@body))

(wcar*
       (car/ping)
       (car/set "foo" "bar")
       (car/get "foo"))

The car namespace includes a function for every Redis command and they're all named the same and accept the same arguments.

In general, you can just pass Clojure values (e.g. maps, vectors) to those functions and they'll be serialized and de-serialized automagically.


Reply to this email directly or view it on GitHub: https://github.com/ptaoussanis/carmine/issues/97#issuecomment-51424458

kenny-evitt commented 9 years ago

@mstram, yes, you're right about the server-conn typo. Give me a minute; I'm trying to slap together a little demo that should help.

kenny-evitt commented 9 years ago

@mstram, here's what you should try:

Based on your comment with the results of my initial suggestion, I'm guessing you cloned this repo and you're trying to run it directly. I'm pretty sure that's not really what you want to do.

First off, you should have Redis installed and running on your development computer and listening on the default port (6379).

Second, let's create a dummy project with Leiningen to isolate exactly what you need to do.

In an open terminal or command line session, in some suitable directory, run the following:

lein new app carmine-demo

That should create a directory named carmine-demo. In that directory, open the file project.clj in your code editor.

Add the carmine dependency to the project.clj file and save it; here's the line you need to change:

:dependencies [[org.clojure/clojure "1.5.1"]]

Change it to these two lines:

:dependencies [[org.clojure/clojure "1.5.1"]
                 [com.taoensso/carmine "2.6.2"]]

From inside the carmine-demo folder in your terminal or command line session, run the following:

lein repl

Now type in the code in my initial suggestion (edited per the typo you identified):

(require '[taoensso.carmine :as car :refer (wcar)]) ; -> nil

(def server-conn nil) ; -> #'carmine-demo.core/server-conn

(defmacro wcar* [& body] `(car/wcar server-conn ~@body)) ; -> #'carmine-demo.core/wcar*

(wcar*
       (car/ping)
       (car/set "foo" "bar")
       (car/get "foo")) ; -> ["PONG" "OK" "bar"]

I created a GitHub repo for this. See the commits – the first is what the initial lein new ... command produced; the second was all you really need to do.

mstram commented 9 years ago

Actually, I'm NOT trying to run the carmine repo.

I'm trying to run your first example from a "clojure" repl i.e. :

java -cp "$HOME/clojure/*" jline.ConsoleRunner clojure.main "$@"

I'm doing that, because 'lein repl' is crashing / not working. (I posted a bug report on the Leiningen repo).

The issue I seem to be running into with your first example is how to specify a dot-jar file (carmine-2.7.0-RC1.jar) in the require command.

I renamed the file to just 'carmine.jar', but now it's looking for taoensso/carmine/jar.clj

This is really getting silly.

I appreciate your efforts !

Mike

On 8/6/14, kenny-evitt notifications@github.com wrote:

@mstram, here's what you should try:

Based on your comment with the results of my initial suggestion, I'm guessing you cloned this repo and you're trying to run it directly. I'm pretty sure that's not really what you want to do.

First off, you should have Redis installed and running on your development computer and listening on the default port (6379).

Second, let's create a dummy project with Leiningen to isolate exactly what you need to do.

In an open terminal or command line session, in some suitable directory, run the following:

lein new app carmine-demo

That should create a directory named carmine-demo. In that directory, open the file project.clj in your code editor.

Add the carmine dependency to the project.clj file and save it; here's the line you need to change:

:dependencies [[org.clojure/clojure "1.5.1"]]

Change it to these two lines:

:dependencies [[org.clojure/clojure "1.5.1"]
                 [com.taoensso/carmine "2.6.2"]]

From inside the carmine-demo folder in your terminal or command line session, run the following:

lein repl

Now type in the code in my initial suggestion (edited per the typo you identified):

(require '[taoensso.carmine :as car :refer (wcar)]) ; -> nil

(def server-conn nil) ; -> #'carmine-demo.core/server-conn

(defmacro wcar* [& body] `(car/wcar server-conn ~@body)) ; ->
#'carmine-demo.core/wcar*

(wcar*
       (car/ping)
       (car/set "foo" "bar")
       (car/get "foo")) ; -> ["PONG" "OK" "bar"]

I created a GitHub repo for this. See the commits - the first is what the initial lein new ... command produced; the second was all you really need to do.


Reply to this email directly or view it on GitHub: https://github.com/ptaoussanis/carmine/issues/97#issuecomment-51428271

ptaoussanis commented 9 years ago

Thanks a lot for the assistance @kenny-evitt, appreciate it :-)

@mstram: Hi Mike, I'd definitely suggest that getting Leiningen working first would be the right way of going about this. The error you're seeing is because Carmine's dependencies aren't available to your REPL session. You've got the right idea on including the Carmine .jar file, but that doesn't include downstream dependencies which can become a major headache to try do manually.

Leiningen handles all of this (and far more) for you, and really should be considered a necessity - especially if you're still finding your Clojure legs. It's mature and very widely used, so if you're running into trouble with it - I'd first suspect a config or platform issue which you might be able to solve with some Googling or maybe the Clojure IRC channel.

I'm not up-to-date on where the best are, but there should be plenty of good guides+docs online for folks new to Clojure. One random example here and some more links here.

Once you've got Leiningen running and you're familiar with the basics of getting a working Leiningen project REPL running, etc. - the Carmine README will make more sense. It's basically a case of adding the Carmine dependency to your project.clj, starting a REPL, and typing stuff in as it is in the README (or copy-pasting @kenny-evitt's sample above).

Hope that helps, and good luck with your Clojure-ing! Cheers :-)

mstram commented 9 years ago

While getting lein working is something I'm definitely working on, Clozure's require syntax / operation is still bizzare.

Plenty of questions on StackOverflow support that idea.

The lein deps operation does seem to be working on my box, as I was able to build the 'uberjar' apparently successfully.

As Require is a built in Clojure function, it should work with / without Lein / or other addon auxilary software. True it won't be as easy (by probably a long margin), but I would like to understand how the "bare bones" works.

Mike

On 8/7/14, Peter Taoussanis notifications@github.com wrote:

Thanks a lot for the assistance @kenny-evitt, appreciate it :-)

@mstram: Hi Mike, I'd definitely suggest that getting Leiningen working first would be the right way of going about this. The error you're seeing is because Carmine's dependencies aren't available to your REPL session. You've got the right idea on including the Carmine .jar file, but that doesn't include downstream dependencies which can become a major headache to try do manually.

Leiningen handles all of this (and far more) for you, and really should be considered a necessity - especially if you're still finding your Clojure legs. It's mature and very widely used, so if you're running into trouble with it - I'd first suspect a config or platform issue which you might be able to solve with some Googling or maybe the Clojure IRC channel.

I'm not up-to-date on where the best are, but there should be plenty of good guides+docs online for folks new to Clojure. One random example here and some more links here.

Once you've got Leiningen running and you're familiar with the basics of getting a working Leiningen project REPL running, etc. - the Carmine README will make more sense. It's basically a case of adding the Carmine dependency to your project.clj, starting a REPL, and typing stuff in as it is in the README (or copy-pasting @kenny-evitt's sample above).

Hope that helps, and good luck with your Clojure-ing! Cheers :-)


Reply to this email directly or view it on GitHub: https://github.com/ptaoussanis/carmine/issues/97#issuecomment-51436152

ptaoussanis commented 9 years ago

While getting lein working is something I'm definitely working on, Clozure's require syntax / operation is still bizzare.

It can be, though note that the issue you're experiencing here isn't because of require but because of your JVM classpath configuration (something that Leiningen will manage for you).

The lein deps operation does seem to be working on my box, as I was able to build the 'uberjar' apparently successfully.

Would need to see your code + Leiningen config (project.clj), and know what error you're seeing when you try to get a Lein REPL. I'd also note that lein deps is actually deprecated (manual calls shouldn't be necessary with Leiningen v2+).

As Require is a built in Clojure function, it should work with / without Lein / or other addon auxilary software.

Sure, it will when the JVM classpath is correctly configured. Leiningen isn't a requirement - but it does take care of a lot of complicated issues for you which can be useful, esp. while you're still finding your feet.

True it won't be as easy (by probably a long margin), but I would like to understand how the "bare bones" works.

Absolutely, understood :-) I would suggest trying to get your environment working with Lein first (since it's easier), then working backwards if you'd like to understand what Lein's doing under the covers.

Closing this since it's not really a Carmine issue. Would recommend checking out some of the getting-started resources online and/or the Clojure Google Group and/or IRC channel. Good luck, cheers! :-)

mstram commented 9 years ago

Hi Peter,

I think I've found the problem.

The nrepl server is trying to run on localhost, but my cloud service (Nitrous.io), requires "0.0.0.0".

I've found the code in cmdline.clj, and changed it

I'm not sure if it will accept that syntax.

Is there some technical reason Maven is required to rebuild it, rather than Clojure / lein ?

Mike