All Projects → redis-store → Redis Rails

redis-store / Redis Rails

Licence: mit
Redis stores for Ruby on Rails

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Redis Rails

Split
📈 The Rack Based A/B testing framework
Stars: ✭ 2,539 (+180.86%)
Mutual labels:  redis, rails
Entangled
Rails in real time
Stars: ✭ 108 (-88.05%)
Mutual labels:  redis, rails
Recommendable
👍👎 A recommendation engine using Likes and Dislikes for your Ruby app
Stars: ✭ 1,340 (+48.23%)
Mutual labels:  redis, rails
Redis web manager
Manage your Redis instance (see keys, memory used, connected client, etc...)
Stars: ✭ 139 (-84.62%)
Mutual labels:  redis, rails
Flipper
🐬 Beautiful, performant feature flags for Ruby.
Stars: ✭ 2,732 (+202.21%)
Mutual labels:  redis, rails
Redis dashboard
Sinatra app to monitor Redis servers.
Stars: ✭ 141 (-84.4%)
Mutual labels:  redis, rails
Gdpr Rails
An example project on building a GDPR compliant application
Stars: ✭ 109 (-87.94%)
Mutual labels:  redis, rails
Datoji
A tiny JSON storage service. Create, Read, Update, Delete and Search JSON data.
Stars: ✭ 222 (-75.44%)
Mutual labels:  redis, rails
Redis Search
Deprecated! High performance real-time prefix search, indexes store in Redis for Rails application
Stars: ✭ 713 (-21.13%)
Mutual labels:  redis, rails
Capybara error intel
🐛 Ruby gem for heuristic error messages in Capybara based Page Objects
Stars: ✭ 16 (-98.23%)
Mutual labels:  rails
Rails5 application template
Rails Application Template
Stars: ✭ 17 (-98.12%)
Mutual labels:  rails
Redis Marshal
Lightweight Redis data exploration tool
Stars: ✭ 16 (-98.23%)
Mutual labels:  redis
Vagrant Rails Dev
my vagrant rails development box
Stars: ✭ 16 (-98.23%)
Mutual labels:  rails
Esp8266 Redis
An Arduino library for Redis that works on ESP8266.
Stars: ✭ 18 (-98.01%)
Mutual labels:  redis
Procourse Memberships
Allow users to purchase access to a user group on Discourse.
Stars: ✭ 16 (-98.23%)
Mutual labels:  rails
Presto Redis
presto-redis is an experimental sql layer for redis
Stars: ✭ 18 (-98.01%)
Mutual labels:  redis
Bh
Bootstrap Helpers for Ruby
Stars: ✭ 834 (-7.74%)
Mutual labels:  rails
Ordinalize full
Turns a number into an ordinal string such as first, second, third or 1st, 2nd, 3rd.
Stars: ✭ 6 (-99.34%)
Mutual labels:  rails
Webside
基于RBAC的完全响应式权限管理系统
Stars: ✭ 19 (-97.9%)
Mutual labels:  redis
Redis poolex
Redis pool using poolboy(connection pool) and exredis(redis client).
Stars: ✭ 18 (-98.01%)
Mutual labels:  redis

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.

A quick note about Rails 5.2

Rails 5.2.0 includes a Redis cache store out of the box, so you don't really need this gem anymore if you just need to store the fragment cache in Redis. Maintenance on the redis-activesupport gem will continue for security and compatibility issues, but we are no longer accepting new features. We are still actively maintaining all other gems in the redis-store family, such as redis-actionpack for session management, and redis-rack-cache for HTTP cache storage.

Installation

Add the following to your Gemfile:

gem 'redis-rails'

Usage

redis-rails packages storage drivers for Redis which implement the ActiveSupport fragment caching and ActionDispatch / Rack session storage APIs. The following section(s) explain how to configure each store:

Rails Fragment Cache

Configure the fragment cache store in config/environments/production.rb like so:

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

The ActiveSupport::Cache::Store implementation assumes that your backend store (Redis, Memcached, etc) will be available at boot time. If you cannot guarantee this, you can use the raise_errors: false option to rescue connection errors.

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"
}, {
  expires_in: 90.minutes
}

Session Storage

If you need session storage, consider directly using redis-actionpack instead.

You can also store your session data in Redis, keeping user-specific data isolated, shared, and highly available. Built upon redis-rack, we present the session data to the user as a signed/encrypted cookie, but we persist the data in Redis.

Add the following to your config/initializers/session_store.rb to use Redis as the session store.

MyApplication::Application.config.session_store :redis_store,
  servers: ["redis://localhost:6379/0/session"],
  expire_after: 90.minutes,
  key: "_#{Rails.application.class.parent_name.downcase}_session",
  threadsafe: true,
  secure: true

A brief run-down of these options...

  • servers is an Array of Redis servers that we will attempt to find data from. This uses the same syntax as :redis_store
  • expire_after is the default TTL of session keys. This is also set as the expiry time of any cookies generated by the session store.
  • key is the name of the cookie on the client side
  • threadsafe is for applications that run on multiple instances. Set this to false if you want to disable the global mutex lock on session data. It's true by default, meaning the mutex will be enabled.
  • signed uses signed/encrypted cookies to store the local session on a client machine, preventing a malicious user from tampering with its contents.
  • secure ensures HTTP cookies are transferred from server to client on a secure (HTTPS) connection
  • httponly ensures that all cookies have the HttpOnly flag set to true

HTTP Caching

We also provide an adapter for Rack::Cache that lets you store HTTP caching data in Redis. To take advantage of this, add the following to Gemfile:

group :production do
  gem 'redis-rack-cache'
end

Then, add the following to config/environments/production.rb:

# 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

You can also use Redis Sentinel to manage a cluster of Redis servers for high-availability data access. To do so, configure the sentinel servers like so:

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
  }]
}

You can then include this in your cache store configuration within config/environments/production.rb:

config.cache_store = :redis_store, sentinel_config.merge(
  namespace: "cache",
  expires_in: 1.days
)
config.session_store :redis_store, {
  servers: [
    sentinel_config.merge(
      namespace: "sessions"
    )
  ],
  expire_after: 2.days
}

Usage with Redis Cluster

You can also specify only a subset of the nodes, and the client will discover the missing ones using the CLUSTER NODES command.

config.cache_store = :redis_store, { cluster: %w[redis://127.0.0.1:6379/0/] }

Running tests

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

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

Status

Gem Version Build Status Code Climate

Copyright

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].