taoensso / carmine

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

pipelining car/get #171

Closed barkanido closed 8 years ago

barkanido commented 8 years ago

Hi, I am trying to pipeline a series of car/get calls and I get unexpected responses (require '[taoensso.timbre :refer [spy]]) (require '[taoensso.carmine :as car]) (def tranid "71wwN8nQJEdEpTHPGrj7sA") (wcar* (:clent db) :as-pipeline (doseq [k [tranid "not-there"]] (spy (car/get k))))

DEBUG - (car/get k) => [nil [["GET" "71wwN8nQJEdEpTHPGrj7sA"]]] DEBUG - (car/get k) => [nil [["GET" "71wwN8nQJEdEpTHPGrj7sA"] ["GET" "kkk"]]] ["some-value" nil]

now the return value is correct: the first key is there and the second is not, but what bothers me is the intermediate return values by car/get. specifically I am interested in

  1. making sure that only a single round trip to redis
  2. insert a gzip call to unzip each value (if it was found).

can you explain the logging?

ptaoussanis commented 8 years ago

Hi Ido,

but what bothers me is the intermediate return values by car/get

Individual Redis command calls (like car/get) always return nil. A call to car/get just queues a Redis command for later execution; the command's reply from Redis is visible only in the return value of the enclosing wcar call.

wcar opens a connection to Redis, executes all enclosed commands in a pipeline, returns all the replies, then releases the connection to Redis.

Does that make sense?

making sure that only a single round trip to redis

That's correct. A single wcar usually implies a single round trip to Redis (there may be exceptions in a few unusual cases for commands that require an immediate response).

insert a gzip call to unzip each value (if it was found).

You can do this either with Carmine's reply parsing feature, or just with Clojure's destructuring:

(let [[-resp1 -resp2] (wcar* (car/get "foo") (car/get "bar"))
       resp1 (unzip -resp1)
       resp2 (unzip -resp2)]
...
)

Does that help? Please feel free to close if you're satisfied, cheers :-)

barkanido commented 8 years ago

that's perfect. thanks!