Clojure + Redis

39 views
Skip to first unread message

Gabi

unread,
Dec 30, 2009, 6:52:34 AM12/30/09
to Clojure
On first look, Redis and Clojure seems to be a perfect match. They
both handle sets and maps efficiently. If one could find an easy way
to store and retrieve Clojure data structures to Redis (even a small
subset- just a list or a set), a distributed clojure app could be very
easy (and effective?) thing to do - The stateless Clojure nodes would
share and operate on the same central data structure which is stored
in Redis). What do you thing ? Is it worth investigating further?

Robert Campbell

unread,
Dec 30, 2009, 10:40:04 AM12/30/09
to clo...@googlegroups.com
I think anything which lowers the impedance mismatch between Clojure
data structures and a persistent store is worth investigating. I'd
love to find an ACID, transactional store which accepts native
structures. Right now I'm using CouchDB, and while JSON is close
enough, it still requires a mapping between the Clojure and Couch
worlds. Not supporting set, and not allowing fields with dashes
(JavaScript thinks it's a minus) are some of the annoyances.

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

Vagif Verdi

unread,
Dec 30, 2009, 3:48:06 PM12/30/09
to Clojure
There are other NoSQL datastores written in java, like Voldemort.
Perhaps if you investigate them, you will find one that will be much
easier to integrate with clojure.

Steve Purcell

unread,
Dec 31, 2009, 5:29:31 AM12/31/09
to clo...@googlegroups.com
Not sure if it's any help, but here's a variant of memoize I wrote, which stores arbitrary readable/printable objects to redis:

http://gist.github.com/266689

(If there's any interest, I'll wrap it up in a github project and push it to clojars.)

Redis isn't a hierarchical store, so its array/set operations would only benefit the most shallow of data structures.

-Steve

Constantine Vetoshev

unread,
Dec 31, 2009, 12:31:04 PM12/31/09
to Clojure
On Dec 30, 10:40 am, Robert Campbell <rrc...@gmail.com> wrote:
> I think anything which lowers the impedance mismatch between Clojure
> data structures and a persistent store is worth investigating. I'd
> love to find an ACID, transactional store which accepts native
> structures.

Have you looked at Cupboard (http://github.com/gcv/cupboard)? It tries
to make it easy to store native Clojure data structures, and it is as
ACID and transactional as the underlying Berkeley DB JE
implementation. If you have looked at it, I'd appreciate some feedback
as to where it fell short of your expectations. :)

I plan to start adding distributed storage support in the next few
months. The latest JE release has master-slave replication, which I
think will work well for Cupboard.

Gabi

unread,
Dec 31, 2009, 11:20:40 AM12/31/09
to Clojure
Yes. I think it is of much interest. What if I stored a shared data
structure in redis (only because its the fastest), using your memoize
variant, and process (maybe even updated it) it in parallel from
different Clojure nodes. Some kind of primitive map/reduce mechanism I
think.

jem

unread,
Dec 31, 2009, 11:59:54 AM12/31/09
to Clojure
Something else to look at might be the Apache Jackrabbit project at
http://jackrabbit.apache.org/.

I've been looking at tools along these lines as well, and recently
looked at Redis for the same reasons. Right now, though, I'm focusing
my attention on Jackrabbit which is an implementation of the JSR170
repository specifications. It supports hierarchical data and lists.
I was looking for some way to save dynamic objects (basically runtime
defined maps) and this looks like it might work.

JSR170 defines a repository as:

"A content repository consists of one or more workspaces, each of
which contains a tree of items. An item is either a node or a
property. Each node may have zero or more child nodes and zero or more
child properties. There is a single root node per workspace, which has
no parent. All other nodes have one parent. Properties have one parent
(a node) and cannot have children; they are the leaves of the tree.
All of the actual content in the repository is stored within the
values of the properties."

The available property types cover what appear to be all the bases,
including references to other nodes to prevent cycles when
serializing. It can support annotated Java objects or use the Node
building capability directly and allows querying similar to XPath.
Since it is a Java project, using it from Clojure should be trivial to
use.

Steve Purcell

unread,
Jan 1, 2010, 6:14:30 AM1/1/10
to clo...@googlegroups.com
There you go: http://github.com/purcell/redis-memo

I doubt the memoize functions provided therein will be directly useful to you, but you may find a few lines of helpful code there. Best of luck with your experiment.

-Steve

Gabi

unread,
Jan 1, 2010, 8:25:58 AM1/1/10
to Clojure
Jackrabbit is heavy. It might be powerful but I am sure it is much
slower than Redis or MongoDB.

On Dec 31 2009, 6:59 pm, jem <jere.mcdev...@gmail.com> wrote:
> Something else to look at might be the Apache Jackrabbit project athttp://jackrabbit.apache.org/.

Julian Morrison

unread,
Jan 1, 2010, 4:07:05 PM1/1/10
to Clojure
I've just recently been poking around these NoSQLs investigating their
features, so...

Redis has limited data structures - flat un-nested lists and sets, and
plain strings. It doesn't have sets exactly - just keys and values.
Nothing nested at all, unless you serialize to strings. No indexes,
although you can hack up your own.

To be honest, Redis isn't that impressive versus what's in Clojure
already. It's an in-memory DB (so it's not much different from ref
+dosync) and it intermittently spits a snapshot to disk. If you can
live with an in-process DB, you could copy (and exceed) its features
including snapshot saving in a page of pure Clojure code, and beat it
on speed too.

Contrast MongoDB: slower because it bothers to save things, but still
around twice as fast as MySQL and much faster than CouchDB (cite: the
benchmarks page). Arbitrarily nested collections, indexes, atomic
updates (in place operations like inc and append, or atomic compare-
and-set), JSON syntax, typed data, replication (built in) and sharding
(via a broker process).

(MongoDB downsides: it grows files in a very greedy way to try and
minimize data fragmentation, and it needs a 64bit machine to store
more than about 2Gb.)

Julian Morrison

unread,
Jan 1, 2010, 4:08:45 PM1/1/10
to Clojure
Oops, typo - I meant, doesn't have hashes.

Gabi

unread,
Jan 1, 2010, 7:12:10 PM1/1/10
to Clojure
I am interested in the idea: Completely stateless set of Clojure nodes
(on many machines), operating on a central state stored in some
datastore.
If transactions could be managed somehow, I think it would be very
compelling model for many applications.

Tom Hicks

unread,
Jan 3, 2010, 7:40:11 PM1/3/10
to Clojure
Have you looked at Neo4J? I have no experience with it but
someone in the forum just announced a Clojure wrapper for it:

http://groups.google.com/group/clojure/browse_thread/thread/9628c622784ff45a#
cheers,
-t

Gabi

unread,
Jan 4, 2010, 4:47:29 AM1/4/10
to Clojure
How about congomongo (http://github.com/somnium/congomongo) ?
Have anybody used it ? Seems good choice for storing state in central
location..

On Jan 4, 2:40 am, Tom Hicks <hickstoh...@gmail.com> wrote:
> Have you looked at Neo4J? I have no experience with it but
> someone in the forum just announced a Clojure wrapper for it:
>

> http://groups.google.com/group/clojure/browse_thread/thread/9628c6227...

Shantanu Kumar

unread,
Jan 4, 2010, 5:51:23 AM1/4/10
to Clojure

On Jan 2, 5:12 am, Gabi <bugspy...@gmail.com> wrote:
> I am interested in the idea: Completely stateless set of Clojure nodes
> (on many machines), operating on a central state stored in some
> datastore.
> If transactions could be managed somehow, I think it would be very
> compelling model for many applications.

Do you mean distributed transactions?

Gabi

unread,
Jan 4, 2010, 5:59:51 AM1/4/10
to Clojure
Maybe, though I would avoid distributed transactions as much as
possible. They are complex and slow creatures.

Gabi

unread,
Jan 4, 2010, 7:15:26 AM1/4/10
to Clojure
What if I wanted to use Redis just persist binary (serialized) clojure
objects ?
What's the easiest (and fastest) way to serialize/de-serialize vectors
or lists in Clojure ? (so the can stored as blobs in Redis)

Steve Purcell

unread,
Jan 4, 2010, 7:55:50 AM1/4/10
to clo...@googlegroups.com
Read the code I posted in this thread and put up on github after you expressed interest.

That's part of what it does, using the reader/printer representation.

Alternatives would include standard Java binary serialisation or 3rd party libraries (Hessian/Burlap?).

-Steve

anders nawroth

unread,
Jan 4, 2010, 12:10:31 PM1/4/10
to Clojure
There's actually been some activity from different people regarding
Clojure + Neo4j, see:
http://wiki.neo4j.org/content/Clojure

/anders

On Jan 4, 1:40 am, Tom Hicks <hickstoh...@gmail.com> wrote:
> Have you looked at Neo4J? I have no experience with it but
> someone in the forum just announced a Clojure wrapper for it:
>

> http://groups.google.com/group/clojure/browse_thread/thread/9628c6227...

Gabi

unread,
Jan 5, 2010, 4:24:19 AM1/5/10
to Clojure
I think you should do "(binding [*print-dup* true] (pr-str value).."
instead of just (pr-str value) in the encode-value function. (line 20
in redis_memo.clj)

Steve Purcell

unread,
Jan 5, 2010, 3:27:59 PM1/5/10
to clo...@googlegroups.com
Indeed, thanks - I realized that earlier today myself!

-Steve

Steve Purcell

unread,
Jan 5, 2010, 3:31:37 PM1/5/10
to clo...@googlegroups.com
Or rather, more importantly, I realised I should bind *print-level* to nil...

As for *print-dup*, I guess there's a danger that stored values might become unreadable if any implementation structure classes were to get renamed in a future clojure release.

-Steve


On 5 Jan 2010, at 09:24, Gabi wrote:

Reply all
Reply to author
Forward
0 new messages