我使用以下代码在redis中设置密钥
(defn save-to-redis[key value]
(let [str-value (json/generate-string value)]
(redis/with-server {:host "127.0.0.1" :port 6379 :db 0}
(redis/set key str-value))))
但是当我通过运行redis-cli检查设置的值时,我看到它返回的是str值的长度而不是str值
我把它剥夺了:
(defn save-to-redis[key value]
(redis/with-server {:host "127.0.0.1" :port 6379 :db 0}
(redis/set "foo" "bar")))
当我使用“redis-cli> get foo”时它响应“3”
我正在查看http://devender.wordpress.com/2010/06/13/redis-and-clojure/上的示例,甚至复制和粘贴他的示例也失败了.我尝试:
(defn test-redis []
(println "testing redis")
(redis/with-server {:host "127.0.0.1" :port 6379 :db 0}
(do
(redis/set "foo" "bar")
(println (redis/get "foo")))))
我明白了
testing redis
Exception: java.lang.Exception: Server error: ERR unknown command 'bar'
internal.clj:123 redis.internal/eval1198[fn]
MultiFn.java:163 clojure.lang.MultiFn.invoke
internal.clj:114 redis.internal/read-reply
internal.clj:112 redis.internal/read-reply
redis.clj:75 redis/get
core.clj:65 spendy.core/test-redis[fn]
internal.clj:48 redis.internal/with-server*
core.clj:62 spendy.core/test-redis
core.clj:74 spendy.core/respond-to-ajax
routes.clj:16 spendy.routes/fn
core.clj:39 compojure.core/if-route[fn]
core.clj:24 compojure.core/if-method[fn]
core.clj:98 compojure.core/routing[fn]
core.clj:2053 clojure.core/some
core.clj:98 compojure.core/routing
RestFn.java:140 clojure.lang.RestFn.applyTo
core.clj:542 clojure.core/apply
core.clj:103 compojure.core/routes[fn]
keyword_params.clj:21 ring.middleware.keyword-params/wrap-keyword-params[fn]
nested_params.clj:64 ring.middleware.nested-params/wrap-nested-params[fn]
params.clj:76 ring.middleware.params/wrap-params[fn]
multipart_params.clj:80 ring.middleware.multipart-params/wrap-multipart-params[fn]
session.clj:40 ring.middleware.session/wrap-session[fn]
cookies.clj:132 ring.middleware.cookies/wrap-cookies[fn]
middleware.clj:12 hiccup.middleware/wrap-base-url[fn]
Var.java:365 clojure.lang.Var.invoke
stacktrace.clj:15 ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:79 ring.middleware.stacktrace/wrap-stacktrace-web[fn]
reload_modified.clj:15 ring.middleware.reload-modified/wrap-reload-modified[fn]
stacktrace.clj:15 ring.middleware.stacktrace/wrap-stacktrace-log[fn]
stacktrace.clj:79 ring.middleware.stacktrace/wrap-stacktrace-web[fn]
jetty.clj:16 ring.adapter.jetty/proxy-handler[fn]
(Unknown Source) ring.adapter.jetty.proxy$org.mortbay.jetty.handler.AbstractHandler$0.handle
HandlerWrapper.java:152 org.mortbay.jetty.handler.HandlerWrapper.handle
Server.java:326 org.mortbay.jetty.Server.handle
HttpConnection.java:542 org.mortbay.jetty.HttpConnection.handleRequest
HttpConnection.java:945 org.mortbay.jetty.HttpConnection$RequestHandler.content
HttpParser.java:756 org.mortbay.jetty.HttpParser.parseNext
HttpParser.java:218 org.mortbay.jetty.HttpParser.parseAvailable
HttpConnection.java:404 org.mortbay.jetty.HttpConnection.handle
SocketConnector.java:228 org.mortbay.jetty.bio.SocketConnector$Connection.run
QueuedThreadPool.java:582 org.mortbay.thread.QueuedThreadPool$PoolThread.run
我没办法.如果它有帮助,这是我的形式:
(ns spendy.core
(:use [hiccup core page-helpers])
(:require redis
[clj-json.core :as json]))
最佳答案 你使用的是哪个版本的redis-clojure?它适用于此:
https://github.com/tavisrudd/redis-clojure