【问题标题】:Is it possible to start resque-web listening to a redis socket?是否可以启动 resque-web 监听 redis 套接字?
【发布时间】:2011-09-14 00:15:47
【问题描述】:

我已禁用 redis 监听端口 6379 并启用 websocket。它在我的应用程序中运行良好,但是当我启动 resque-web 时,它一直在通过网络接口监听并失败并显示消息:

无法连接到 Redis! (redis://127.0.0.1:6379/0)

有人知道是否可以让 resque-web 使用套接字而不是网络?

提前致谢

【问题讨论】:

    标签: redis resque


    【解决方案1】:

    我一直在阅读 resque-web 的代码,我意识到它会在内部加载您提供的任何路径作为命令的参数。所以我创建了一个普通的 ruby​​ 脚本,它使用 redis gem 连接到 Redis,然后将此实例分配给 Resque.redis:

    刚刚创建了一个名为“resque-web-hack.rb”的文件:

    require 'redis'
    require 'resque'
    $redis = Redis.new(:path => '/tmp/redis.sock')
    Resque.redis = $redis
    

    然后像这样使用它:

    $ resque-web /path/to/my/file/resque-web-hack.rb
    

    这只是一个 hack,但它现在对我有用...

    【讨论】:

      【解决方案2】:

      我刚刚解决了同样的问题 :) 所以这里是解决方案

      在我的 ./config/resque.yml 我有这一行

      development: /tmp/redis.sock
      

      这是我的 RAILS_ROOT/config/initializers/resque.rb

      rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
      rails_env = ENV['RAILS_ENV'] || 'development'
      
      resque_config = YAML.load_file(rails_root + '/config/resque.yml')
      if resque_config[rails_env] =~ /^\// # using unix socket
          Resque.redis = Redis.new(:path => resque_config[rails_env])
      else 
         Resque.redis = resque_config[rails_env]
      end
      

      【讨论】:

      • 我有一个初始化程序,它做了类似的事情,但对我来说,它只解决了与 redis 工作人员的连接。无论如何,我已经为这个对我有用的问题写了一个临时解决方案的答案。无论如何感谢您的回答:-)
      猜你喜欢
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      • 2011-02-15
      • 2014-11-12
      • 2015-12-29
      • 2018-05-16
      • 1970-01-01
      相关资源
      最近更新 更多