gpt4 book ai didi

clojure redis set是设置值的字符串的长度而不是值

转载 作者:IT王子 更新时间:2023-10-29 05:59:59 27 4
gpt4 key购买 nike

我正在使用以下代码在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-value 的长度而不是 str-value

我已经将其简化为:

(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 表单:

(ns spendy.core
(:use [hiccup core page-helpers])
(:require redis
[clj-json.core :as json]))

最佳答案

您使用的是哪个版本的 redis-clojure?它适用于此:https://github.com/tavisrudd/redis-clojure

关于clojure redis set是设置值的字符串的长度而不是值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7775033/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com