【问题标题】:key holding wrong kind of value in redis when pushing data on a list将数据推送到列表时,键在 redis 中持有错误类型的值
【发布时间】:2011-06-02 16:02:43
【问题描述】:

我正在我的 heroku 应用程序上尝试 redis。我在config/initializers/redis.rb中有以下代码

uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

我正在控制台中尝试以下操作,但出现错误:

irb(main):003:0> REDIS.rpush ('foo','bar')
(irb):3: warning: don't put space before argument parentheses
RuntimeError: -ERR Operation against a key holding the wrong kind of value

【问题讨论】:

    标签: ruby-on-rails redis


    【解决方案1】:

    当您尝试对列表值进行操作时返回此错误,而键持有另一种类型的值(例如字符串、集合等)。要找出foo中存储的值的类型,可以使用以下命令:

    REDIS.type("foo")
    

    当您对不包含值的键执行RPUSHLPUSH 时,将自动创建一个列表。因此,您必须确保 foo 不存在或持有列表值,此操作才能正常工作。

    【讨论】:

      猜你喜欢
      • 2015-11-27
      • 2016-10-24
      • 2021-05-25
      • 1970-01-01
      • 2019-10-07
      • 2022-06-10
      • 2018-06-01
      • 2018-10-18
      • 2017-07-06
      相关资源
      最近更新 更多