rails中使用resque
庚寅[虎]年 十月廿七
1.安装
sudo apt-get install redis-server
gem install resque
gem install redis
2.配置
redis配置
vim /etc/redis/redis.conf (根据自身需要进行相应修改)
vim APP/config/initializers/load_redis.rb
require 'redis'
$redis = Redis.new :host =〉 '127.0.0.1' # default port : 6379
vim APP/config/initializers/load_resque.rb
首先: require 'resque'
# Resque.redis设置几种方式
a). Resque.redis = $redis
b). Resque.redis = 'localhost:6379'
c). vim config/resque.yml
内容:
development: localhost:6379
test: localhost:6379
staging: redis1.se.github.com:6379
fi: localhost:6379
production: redis1.ae.github.com:6379
#接着 vim config/initializers/load_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')
Resque.redis = resque_config[rails_env]
3.启动redis-server
$〉 sudo redis-server /etc/redis/redis.conf
4.测试运转
a) scaffold: ./script/server scaffold post title:string body:text
b) 迁移: rake db:migrate
c) 添加TaskJob:
vim app/models/job.rb
Notes: 'Resque jobs are any Ruby classes (or modules) which respon
。
。