How do I use an existing Redis connection in Vanity?

180 Views Asked by At

I have a Redis add-on in Heroku that only allows 10 connections. My app already uses Redis with $redis. I have Unicorn with 3 workers and 2 dynos, which is 6 connections. Vanity connects by itself which is another 6 connections. That is 12 connections which is over the limit of 10. How do I use the existing $redis connection for Vanity so Vanity and my app share the connection?

I saw this deprecated method, but when I try it, it gives an error and stack trace. It was probably for an old version of Redis client.

http://rdoc.info/gems/vanity/Vanity/Playground#redis%3D-instance_method

I use establish_connection in my Unicorn.rb file to connect, and pass it the connection string. I would like to set the connection or Redis client object directly.

http://rdoc.info/gems/vanity/Vanity/Playground#establish_connection-instance_method

Ruby 2.0.0, Rails 4.0.3, Vanity 1.9.0.

1

There are 1 best solutions below

2
Winfield On

You can use the Vanity Playground object programmatically and pass in a Redis adapter with an existing redis instance.

Vanity.playground.establish_connection { :adapter => :redis, :redis => $redis }

This is specified in the vanity configuration guide.