0

I am trying to locate to set the Redis cache setting on the Ruby on Rails project, but I am not able to find the path to set it up.

As I was looking on /etc/redis/redis.conf but I don't see anything related to Ruby on rails to update.

Is there a path for ruby on rails where I need to update the local or external Redis cache endpoint need to be updated?

2
  • Are you trying to tell your Rails application where Redis is located on your computer so that the Rails application can use it ? Commented Nov 29, 2020 at 0:45
  • Yes, I'm looking for the same setting where do I define the Redis settings on Rails? Commented Nov 30, 2020 at 12:22

1 Answer 1

1

You can create config/redis.yml like this :

development:
  url: redis://localhost:6379/
  db: 0
 
production:
  url: 
  db: 0

test: 
  url: redis://localhost:6379/
  db: 1  

And then create an initializer config/initializrs/redis.rb like this

conf = Rails.application.config_for(:redis)
REDIS = Redis.new(conf)

Now in your Rails app, you can use : REDIS.set("today","monday")

REDIS.get("today") will return "monday".

Also you can use Rails.application.config_for(:redis) to make a reference to your Redis config in any other intitializer

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.