Giter VIP home page Giter VIP logo

redis-geo-cache's Introduction

Redis Geo Cache

This is an example Redis configuration that runs a primary Redis in one region and replicas in other regions. Writes to the primary region propagate, writes to other regions are region local.

Redis includes a replica-read-only no setting that makes it especially effective for geo caching. When you run replicas that allow writes, you can write to the closest replica for most ephemeral cache data, and write to the master for commands that should propagate.

Usage

This is a Fly app that requires volumes. Assuming you want a primary redis in the scl region and a replica in the ord region, this is what you need to do.

  1. Clone this repository
  2. fly launch, choose to import the existing config
  3. Choose n when it asks if you want to deploy
  4. Set a redis password: fly secrets set REDIS_PASSWORD=<password>
  5. Create a volume in your primary region:
    fly volumes create redis_server --size 10 --region scl
    
  6. fly deploy
  7. Add volumes in other regions:
    fly volumes create redis_server --size 10 --region ord
    
  8. Add instances: fly scale count 2

Connecting from your application

You should run your application in the same regions as Redis, and use the region specific addresses to connect. It's helpful to set a matching PRIMARY_REGION environment variable on any application you connect to your Redis cluster so you can make choices about where to send writes.

The primary Redis URL is:

# format
redis://x:<password>@<primary-region>.<appname>.internal:6379

# example in scl
redis://x:[email protected]:6379

Read replicas are similar, but using a different region prefix (the $FLY_REGION environment variable is handy here).

To generate a local read replica with Node.js, you might do something like:

const primary = new URL("redis://x:[email protected]:6379")
const replica = new URL(primary)
replica.hostname = `${process.env['FLY_REGION']}.my-redis-app.internal`
replica.toString()
// 'redis://x:[email protected]:6379'

redis-geo-cache's People

Contributors

dannylindquist avatar mrkurt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

redis-geo-cache's Issues

Missing documentation?

Hi, this example demonstrates how to connect to a single primary. I'm missing the configuration and documentation of how the "GEO" cache is used.

  • What happens if the primary is down?
  • How to load balance between replicas?
  • How to rebalance new replicas without restarting the app?
  • How to monitor the cache?

Thanks

Region boot order

@mrkurt, thank you for this. The dig of the ipv6 address is a neat trick.

Although, I believe there is an issue with this approach - Fly provides no assurance that the primary boots before other regions.

My tests indicate, that often times, the replica regions boot on a deploy, prior to the primary, resulting in a broken replica address in the redis conf, once the primary finishes booting and replaces the previous instance. If the replica boots before the primary, the dig query returns the address of the previous primary instance, which will no longer exist once the new primary finishes booting.

Unless I am mistaken, this system fails to take into account of boot order of regions. This model only works if you deploy once, to one region and then scale to additional regions. Redeploying has the potential of breaking replication of data.

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.