0
\$\begingroup\$

The following code handles querying for user data in a multitenant Cassandra database. Each tenant has their own keyspace and within that keyspace data about each tenants users is stored.

This code will run as part of a webservice.

I'm looking on comments for how I handled managing the session so that connection pooling is used and only one session is made.

(defn- session []
 (cc/connect ["localhost"]
 {:credentials
 {:username "" 
 :password ""}}))
(def memo-session (memoize session))
(defn get-recs-by-user-id [client-name client-id user-id]
 (cql/use-keyspace (memo-session) client-name)
 (cql/select (memo-session) "user_recommendations"
 (where [[= :client_id client-id] [= :user_id user-id]])
 (limit 1)))
asked Mar 24, 2015 at 11:53
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

This doesn't feel idiomatic to me.

I would prefer to use an atom or a dynamic variable if you must store the session outside, but really you should probably be passing the session in on each call.

answered Jul 11, 2015 at 23:17
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.