`
dadadada2x
  • 浏览: 9309 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

rails中使用redis实现页面全局记数

阅读更多
curl -O http://redis.googlecode.com/files/redis-2.2.2.tar.gz
tar xzf redis-2.2.2.tar.gz
cd redis-2.2.2
make
cp src/redis-server src/redis-cli /usr/bin
redis-server

First step, add redis-rb to your Gemfile:
gem 'redis', '2.1.1'
Then install the gem via Bundler:
bundle install
Lastly, create an initializer in config/initializers/redis.rb and add the following:
$redis = Redis.new(:host => 'localhost', :port => 6379)
This will create a new instance of the Redis client, connected to localhost:6379 (the default), and store it in the global variable $redis.
Let’s check that everything is working by firing up rails console:
]]> $redis=> #<Redis client v2.1.1 connected to redis://localhost:6379/0 (Redis v2.2.2)> ]]> $redis.set('chunky', 'bacon')=> "OK" ]]> $redis.get('chunky')=> "bacon"
用screen进入后台起
screen -R redis
redis-server

control + a + d 

启动rails + c

$redis.hset 'counter','scaner',50000
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics