Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redis-redirect

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-redirect

  • 0.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

RedisRedirect

Simple redirector for a Rails app. Stores the key in redis (using namespace to stay out of the way) and redirects to the value.

it's a gem, do all that Gemfile stuff:

gem 'redis-redirect'

create a config/initializer/redis_redirect.rb like:

# Load config and set redis.
redis_config = YAML.load_file(rails_root + '/config/redis.yml')[rails_env]
RedisRedirect.redis = Redis.connect(:url => "redis://#{redis_config['host']}/#{redis_config['db']}")

# Set namespace to prevent collisions
RedisRedirect.redis.namespace = "redis_redirect"  # default is redis_redirect

and hook it up to your routes file:

get "*path" => RedisRedirect::Routes

remember routes are run in order, you probably want the redirect pretty low. If the route is not matched, or the connection fails it will just continue down the routes.

This gem creates a model, Redirect, that has source and target instance variables. The Redirect model tries to act a bit like an ActiveRecord object so that form generation is easy. Notable differences is that there is no id field since the datastore is redis. Instead it uses the key to act as a to_param. so:

r = Redirect.new(source: '/some-old-path', target: '/new-hotness')
r.save

same_r = Redirect.find('/some-old-path')
same_r.destroy # works

Should work with Rails 3+, patches welcome.

FAQs

Package last updated on 09 Jan 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc