Coder Social home page Coder Social logo

Comments (6)

supercaracal avatar supercaracal commented on June 12, 2024 1

There is only the latter way unless using sentinel or cluster mode.

w = Redis.new(url: 'redis://your-primary-endpoint')
r = Redis.new(url: 'redis://your-reader-endpoint')

w.set('foo', 1)
r.get('foo')

from redis-rb.

supercaracal avatar supercaracal commented on June 12, 2024

You can specify a reader endpoint like this:

r = Redis.new(url: 'rediss://your-reader-endpoint', reconnect_attempts: 10, reconnect_delay: 1.5, reconnect_delay_max: 10.0)

r.get('foo')

https://aws.amazon.com/about-aws/whats-new/2019/06/amazon-elasticache-launches-reader-endpoint-for-redis/

from redis-rb.

waitstime avatar waitstime commented on June 12, 2024

Thank you, @supercaracal, for your response, I'm aware of the reader endpoint. Is there a way to have a single Redis client connection that manages splitting read only calls between the primary endpoint and the reader endpoint and directs write calls to the primary endpoint? Or is it necessary to write special logic myself to handle multiple client connections (primary and reader) and directing calls to an endpoint based on the redis call?

from redis-rb.

waitstime avatar waitstime commented on June 12, 2024

Thanks for the info! Closing this.

from redis-rb.

dominicfollett avatar dominicfollett commented on June 12, 2024

@supercaracal Apologies for commenting on this closed ticket. But I'd like to ask for clarification.

I have an AWS Elasticache (cluster mode disabled) replication group with a write primary endpoint, and a readonly endpoint. In my scenario I am configuring Rails' cache store:

  config.cache_store = :redis_cache_store, {
    url: [
      ENV['REDIS_WRITE_HOST'],
      ENV['REDIS_READ_HOST'],
    ],
    ...

As it stands, I think I might run into problems with write operations being made on the readonly endpoint. You mention above that using cluster mode is a potential option. How would I leverage redis-clustering with ActiveSupport::Cache for my use-case? Thank you.

from redis-rb.

supercaracal avatar supercaracal commented on June 12, 2024
rcc = Redis::Cluster.new(nodes: "ENV['ELASTICACHE_ENDPOINT_URL']", replica: true, replica_affinity: :latency)
config.cache_store = :redis_cache_store, { redis: rcc }

The above setting might work for you if you use the redis gem version 5.* or later. Also, Redis cluster (cluster mode is enabled in ElastiCache) has some constraints because it does sharding. If bulk processing commands such as MSET, MGET, pipelining, and transaction features are used in redis_cache_store internally, some errors may occur. And clients need consideration of the replication delay. Sorry, I'm not familiar with redis_cache_store codes.

https://github.com/rails/rails/blob/main/activesupport/lib/active_support/cache/redis_cache_store.rb

from redis-rb.

Related Issues (20)

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.