Nov 17, 20266 min read

Migrate Render Redis to Amazon ElastiCache

Move data from a Render Key Value (Redis-compatible) instance to ElastiCache in your own AWS account, either by copying keys lazily on first read or by exporting keys over the Redis protocol during a write freeze.

Illustration for Migrate Render Redis to Amazon ElastiCache

A Redis-compatible Key Value instance on Render is a managed datastore next to the app, reached from other services in the same region over the private network. It works well while everything lives on Render, but once the app moves to AWS the data in it, such as sessions or shopping carts with a TTL, has to reach Amazon ElastiCache without logging users out.

This guide moves that data to ElastiCache in your own AWS account. It starts with Encore, which provisions ElastiCache from Go and copies keys lazily on first read, then covers a SCAN and DUMP pass for keyspaces that cannot wait for a TTL to expire.

Ways to move Render Redis to ElastiCache at a glance

Encore lazy copySCAN / DUMP during a freezeStart empty
Write freezeNoYesNo
Best forKeys with a TTL, such as sessions and cartsLarge or permanent keyspacesPure caches
Render access neededDuring the copy windowOnce, for the exportNo
TargetElastiCache provisioned from GoElastiCache you provisionElastiCache you provision

Reaching Render Key Value from outside

Render keeps the instance private by default, so reading it from AWS or your laptop means enabling external connections, which require TLS and an IP allow list. The dashboard gives a rediss:// URL and a redis-cli --tls command. Inventory the keyspace before choosing a strategy:

~
$ redis-cli --tls -u "$RENDER_REDIS_URL" INFO keyspace$ redis-cli --tls -u "$RENDER_REDIS_URL" --scan --pattern 'session:*' | head$ redis-cli --tls -u "$RENDER_REDIS_URL" PTTL session:8b1f0c$ redis-cli --tls -u "$RENDER_REDIS_URL" INFO server | grep redis_version

SAVE and BGSAVE have historically been disabled on Render Redis, so do not plan the cutover around redis-cli --rdb until you have proven that command against your instance. A lazy copy or a SCAN plus DUMP/RESTORE pass does not depend on those commands.

How do you migrate Render Redis to ElastiCache with Encore?

Encore

Encore brings infrastructure from code: the Redis cluster and a typed keyspace are declared in the service that uses them, and deploying to AWS creates ElastiCache, as listed in the AWS infrastructure docs. Render stays online as the source for keys that have not been copied yet, while the new keyspace fills up from live traffic.

A coding agent can add the keyspace and the fallback load path in the same change. The Render URL is an Encore secret: production values are not stored in the repository, so an agent cannot read those from git. A local override in .secrets.local.cue is a file on disk and is readable.

Set up the app

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

// sessions/sessions.go package sessions import ( "context" "time" "encore.dev/beta/errs" "encore.dev/storage/cache" "github.com/redis/go-redis/v9" ) var cluster = cache.NewCluster("sessions", cache.ClusterConfig{ EvictionPolicy: cache.AllKeysLRU, }) type Session struct { UserID string `json:"user_id"` } var Sessions = cache.NewStructKeyspace[string, Session](cluster, cache.KeyspaceConfig{ KeyPattern: "session/:key", DefaultExpiry: cache.ExpireIn(30 * 24 * time.Hour), }) // RENDER_REDIS_URL from External Access. Remove this field after the copy window. var secrets struct { RenderRedisURL string } func source(ctx context.Context) (*redis.Client, error) { opt, err := redis.ParseURL(secrets.RenderRedisURL) if err != nil { return nil, err } return redis.NewClient(opt), nil } //encore:api private method=GET path=/sessions/:id func Get(ctx context.Context, id string) (*Session, error) { sess, err := Sessions.Get(ctx, id) if err == nil { return &sess, nil } else if !errs.Is(err, cache.Miss) { return nil, err } return load(ctx, id) } func load(ctx context.Context, id string) (*Session, error) { rdb, err := source(ctx) if err != nil { return nil, err } defer rdb.Close() key := "session:" + id raw, err := rdb.HGetAll(ctx, key).Result() if err != nil { return nil, err } var sess Session if err := mapHash(raw, &sess); err != nil { return nil, err } ttl, err := rdb.PTTL(ctx, key).Result() if err != nil { return nil, err } if ttl == -2 { return nil, cache.Miss // expired between HGETALL and PTTL } if ttl == -1 { err = Sessions.With(cache.NeverExpire).SetIfNotExists(ctx, id, sess) } else { err = Sessions.With(cache.ExpireIn(ttl)).SetIfNotExists(ctx, id, sess) } if errs.Is(err, cache.KeyExists) { cur, err := Sessions.Get(ctx, id) if err != nil { return nil, err } return &cur, nil } else if err != nil { return nil, err } // Delete the Render key only if every hash field still matches the snapshot we copied. args := make([]any, 0, len(raw)*2) for field, val := range raw { args = append(args, field, val) } kept, err := rdb.Eval(ctx, ` if #ARGV % 2 ~= 0 then return 0 end local expected = {} for i = 1, #ARGV, 2 do expected[ARGV[i]] = ARGV[i+1] end local cur = redis.call("HGETALL", KEYS[1]) if #cur ~= #ARGV then return 0 end for i = 1, #cur, 2 do if expected[cur[i]] ~= cur[i+1] then return 0 end end return redis.call("DEL", KEYS[1]) `, []string{key}, args...).Int() if err != nil { return nil, err } if kept == 0 { // The source changed. Drop the target only if it still equals the snapshot // this request wrote; keep a newer target write. dest, err := Sessions.Get(ctx, id) if err == nil && dest != sess { return &dest, nil } if err != nil && !errs.Is(err, cache.Miss) { return nil, err } if err == nil { _, _ = Sessions.Delete(ctx, id) } newerRaw, err := rdb.HGetAll(ctx, key).Result() if err != nil { return nil, err } var newer Session if err := mapHash(newerRaw, &newer); err != nil { return nil, err } return &newer, nil } return &sess, nil } func mapHash(raw map[string]string, sess *Session) error { if len(raw) == 0 { return cache.Miss } if v, ok := raw["UserID"]; ok { sess.UserID = v } else { sess.UserID = raw["user_id"] } if sess.UserID == "" { return cache.Miss } return nil }

Set the Render URL as a production secret and deploy. A key with no expiry (PTTL of -1) is written with cache.NeverExpire rather than a default TTL. The source key is deleted only when every hash field still matches the snapshot that was copied. If a newer source write landed first, the ElastiCache copy is dropped only when it still equals that snapshot, so a newer target write is kept. After the longest TTL has passed, remove the secret field and the fallback, deploy, and turn off external access on Render. Encore provisions an IAM role for the service.

Best fit: apps moving from Render to their own AWS account whose Redis data has a natural expiry, with no freeze on writes.

SCAN, DUMP and RESTORE by hand

For a large keyspace or data without a TTL, stop writers, SCAN the instance, and DUMP/RESTORE each key with its PTTL into ElastiCache. Use the TLS URL for Render and a TLS-capable redis-cli against ElastiCache in a private subnet or through a tunnel. Prove the pass on a copy of the data first.

Best fit: permanent keyspaces where a short write freeze is acceptable.

How to choose

Pick Encore with a lazy copy when the data expires on its own and you want ElastiCache created from the service code. Pick a SCAN and DUMP pass when the keyspace is large or permanent and a write freeze is fine. Let pure caches start empty either way.

Frequently asked questions

How do I export data from Render Redis?

Enable external access on the Key Value instance, allow your IP, and connect with redis-cli --tls and the rediss:// URL from the External Access section of the Render dashboard. Inventory the keyspace with INFO and SCAN. A full redis-cli --rdb snapshot may fail if SAVE and BGSAVE are disabled, so prefer a lazy copy or a SCAN, DUMP and RESTORE pass.

How do I migrate Render Redis to ElastiCache with Encore?

Declare the cluster with cache.NewCluster and a typed keyspace, store the Render rediss:// URL as an Encore secret, and on a cache miss read the old key and its PTTL from Render with go-redis. Preserve a PTTL of -1 as no expiry, write with SetIfNotExists, and delete the old key only if it still holds the snapshot you copied. Encore provisions ElastiCache in your AWS account on deploy.

Do I need to migrate a Redis cache at all?

If the instance is a pure cache that can be rebuilt from Postgres or an API, start ElastiCache empty and let the app refill it. Migrate only keys that would log users out or drop work in progress, such as sessions, carts or queues.

How do I connect to Render Key Value from my laptop?

Turn on external connections in the Render dashboard, add your IP to the allow list and use the TLS redis-cli command Render shows in the External Access section. The scheme is rediss, not redis. Turn external access off again when the migration is finished.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders