【问题标题】:NoMethodError (undefined method `slice!' for nil:NilClass) from Redis call来自 Redis 调用的 NoMethodError (undefined method `slice!' for nil:NilClass)
【发布时间】:2015-08-02 05:33:14
【问题描述】:

我随机收到以下错误消息。有谁知道是什么原因造成的?

NoMethodError (undefined method `slice!' for nil:NilClass):
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/connection/ruby.rb:274:in `read'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:248:in `block in read'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:236:in `io'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:247:in `read'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:112:in `block in call'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:217:in `block (2 levels) in process'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:353:in `ensure_connected'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:207:in `block in process'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:292:in `logging'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:206:in `process'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis/client.rb:112:in `call'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis.rb:789:in `block in get'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis.rb:37:in `block in synchronize'
 /usr/local/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
 vendor/bundle/ruby/2.1.0/gems/redis-3.2.1/lib/redis.rb:788:in `get'
 vendor/bundle/ruby/2.1.0/gems/redis-store-1.1.4/lib/redis/store/interface.rb:5:in `get'
 vendor/bundle/ruby/2.1.0/gems/redis-store-1.1.4/lib/redis/store/marshalling.rb:17:in `get'
 vendor/bundle/ruby/2.1.0/gems/redis-activesupport-4.0.0/lib/active_support/cache/redis_store.rb:169:in `read_entry'
 vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.9/lib/active_support/cache.rb:312:in `block in read'
 vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.9/lib/active_support/cache.rb:548:in `instrument'
 vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.9/lib/active_support/cache.rb:311:in `read'
 /var/www/apps/13712/shared/vendor_bundle/ruby/2.1.0/bundler/gems/spree-13f1df56d58f/core/app/models/spree/preferences/store.rb:34:in `get'
 /var/www/apps/13712/shared/vendor_bundle/ruby/2.1.0/bundler/gems/spree-13f1df56d58f/core/app/models/spree/preferences/scoped_store.rb:13:in `fetch'
 /var/www/apps/13712/shared/vendor_bundle/ruby/2.1.0/bundler/gems/spree-13f1df56d58f/core/app/models/spree/preferences/preferable_class_methods.rb:13:in `block in preference'
 /var/www/apps/13712/shared/vendor_bundle/ruby/2.1.0/bundler/gems/spree-13f1df56d58f/core/app/models/spree/preferences/preferable.rb:43:in `get_preference'
 vendor/bundle/ruby/2.1.0/bundler/gems/spree-13f1df56d58f/core/lib/spree/core/controller_helpers/ssl.rb:8:in `block (2 levels) in <module:SSL>'

last place Spree 在调用 redis-rb 之前被命中:

  unless (val = @cache.read(key)).nil? 
     return val 
   end 

在哪里@cache = Rails.cache

更新

我将这个 gem 与这个 SSL plugin 一起使用,所以错误可能与插件有关。

line = @sock.getsnil 时会发生错误。这是当地人确定为真的之后。

[1] pry(#<Redis::Connection::Ruby>)> line
=> nil
[2] pry(#<Redis::Connection::Ruby>)> @sock
=> #<OpenSSL::SSL::SSLSocket:0x007fdab2688730
 @callback_state=nil,
 @context=
  #<OpenSSL::SSL::SSLContext:0x007fdab2688758
   @ca_file=nil,
   @ca_path=nil,
   @cert=nil,
   @cert_store=nil,
   @client_ca=nil,
   @client_cert_cb=nil,
   @extra_chain_cert=nil,
   @key=nil,
   @npn_protocols=nil,
   @npn_select_cb=nil,
   @options=nil,
   @renegotiation_cb=nil,
   @servername_cb=nil,
   @session_get_cb=nil,
   @session_id_context=nil,
   @session_new_cb=nil,
   @session_remove_cb=nil,
   @timeout=nil,
   @tmp_dh_callback=nil,
   @verify_callback=nil,
   @verify_depth=nil,
   @verify_mode=nil>,
 @eof=true,
 @hostname=nil,
 @io=#<Redis::Connection::TCPSocket:fd 11>,
 @rbuffer="",
 @sync=true,
 @sync_close=false,
 @wbuffer="">
[3] pry(#<Redis::Connection::Ruby>)> @sock.closed?
=> false

【问题讨论】:

    标签: ruby redis


    【解决方案1】:

    这看起来可能是 ruby​​ redis 客户端的问题。

    您可以尝试降级版本和/或向 redis 团队 in the Github repository 提交问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-19
      • 2016-08-13
      • 1970-01-01
      • 2016-01-02
      • 2012-08-08
      • 2014-09-05
      相关资源
      最近更新 更多