开发者

Can you use Redis alongside Resque?

开发者 https://www.devze.com 2023-03-28 11:35 出处:网络
I\'m using Redis To Go on Heroku, and I\'d like to use it to store some data alongside Resque jobs, much like I can store DelayedJobs in the same Postgres database as the rest of my model data.

I'm using Redis To Go on Heroku, and I'd like to use it to store some data alongside Resque jobs, much like I can store DelayedJobs in the same Postgres database as the rest of my model data.

Is this possible? Care to explain briefly how Res开发者_Go百科que stores jobs in Redis? I'm new to Redis, and though I understand on a higher level how it works, I'm unfamiliar with the implementation details.


Yes, you can. According to the Resque documentation:

Resque has a redis setter which can be given a string or a Redis object. This means if you're already using Redis in your app, Resque can re-use the existing connection.

Also, the documentation for Resque.redis= states that a namespace is accepted, to prevent clashes with your other apps running on the same instance:

A 'hostname:port/namespace' String (to set the Redis namespace)

Check out the "Configuration" section of the Resque readme for more information: https://github.com/resque/resque/blob/master/README.markdown


Redis is an advanced key value store which is used by Resque to store data about jobs. Exact details depend on your application however the two should be fine working together. As long as your code stays away from using the lists Resque uses then you will be golden.


yes, completely agree with other answers, the Redis can be used for other purposes, not only for background processing. By the way, Rescue provides easy interface to setup/config/use/browse Redis.

Setup/Run

$ git clone --depth=1 git://github.com/defunkt/resque.git
$ cd resque
$ rake redis:install dtach:install

$ vim config/resque.yml
  "development: localhost:6379"

$ vim config/initializers/rescue.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')
   Resque.redis = resque_config[rails_env]"

$ rake redis:start

Use

# model
 def user_activity
   a = Resque.redis.lrange "log_" + self.id.to_s, 0, -1
   a.map{|i| JSON.parse(i)}
 end

Browse

 $ resque-web

It allows you to browse Redis content, not only background processing

0

精彩评论

暂无评论...
验证码 换一张
取 消