Giter VIP home page Giter VIP logo

redis-rails's Introduction

Redis stores for Ruby on Rails

redis-rails provides a full set of stores (Cache, Session, HTTP Cache) for Ruby on Rails. See the main redis-store readme for general guidelines.

Installation

Add the following to your Gemfile:

gem 'redis-rails'

To use with Rails 3.1+, pin the gem to the latest 4.0 version:

gem 'redis-rails', '~> 4'

Usage

# config/application.rb
config.cache_store = :redis_store, "redis://localhost:6379/0/cache", { expires_in: 90.minutes }

Configuration values at the end are optional. If you want to use Redis as a backend for sessions, you will also need to set:

# config/initializers/session_store.rb
MyApplication::Application.config.session_store :redis_store, servers: "redis://localhost:6379/0/session"

You can also provide a hash instead of a URL

config.cache_store = :redis_store, { 
  host: "localhost",
  port: 6379,
  db: 0,
  password: "mysecret",
  namespace: "cache"
}

And similarly for the session store:

MyApplication::Application.config.session_store :redis_store, servers: { host: "localhost",
                                                                         port: 6379,
                                                                         db: 0,
                                                                         password: "mysecret",
                                                                         namespace: "session"
                                                                       },
                                                                       expires_in: 90.minutes

And if you would like to use Redis as a rack-cache backend for HTTP caching, add redis-rack-cache to your Gemfile and add:

# config/environments/production.rb
config.action_dispatch.rack_cache = {
  metastore: "redis://localhost:6379/1/metastore",
  entitystore: "redis://localhost:6379/1/entitystore"
}

Usage with Redis Sentinel

sentinel_config = {
  url: "redis://mymaster/0",
  role: "master",
  sentinels: [{
    host: "127.0.0.1",
    port: 26379
  },{
    host: "127.0.0.1",
    port: 26380
  },{
    host: "127.0.0.1",
    port: 26381
  }]
}

# configure cache, merging opts with sentinel conf
config.cache_store = :redis_store, sentinel_config.merge(
  namespace: "cache",
  expires_in: 1.days
)

# configure sessions, setting the sentinel config as the
# servers value, merging opts with the sentinel conf.
config.session_store :redis_store, {
  servers: sentinel_config.merge(
    namespace: "sessions"
  ),
  expires_in: 2.days
}

Running tests

gem install bundler
git clone git://github.com/redis-store/redis-rails.git
cd redis-rails
bundle install
bundle exec rake

If you are on Snow Leopard you have to run env ARCHFLAGS="-arch x86_64" bundle exec rake

Status

Gem Version Build Status Code Climate

Copyright

2009 - 2011 Luca Guidi - http://lucaguidi.com, released under the MIT license

redis-rails's People

Contributors

radar avatar tubbo avatar jodosha avatar marceloboeira avatar shiro16 avatar dansimpson avatar greysteil avatar jaredbeck avatar milesmatthias avatar n-rodriguez avatar rstacruz avatar ryanmark avatar hilotter avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.