Skip to content

Commit

Permalink
Redis updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dzirtusss committed May 10, 2024
1 parent 4f417df commit 9cd7951
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 14 deletions.
32 changes: 24 additions & 8 deletions docs/redis.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# Migrating Redis database from Heroku infrastructure
# Migrating Redis databases

**General considerations:**
There are two templates examples in this repo:
- `redis` - basic non-persistent template. It is good for review-apps or staging or where no persistence is required
- `redis2` - basic persistent template. Good for production where persistence is needed, but cluster is overkill.

## Option 1: use SLAVEOF (easier way)

1. create a redis workload that will accept data
2. execute `SLAVEOF source_host source_port`, if needed use `masterauth` to provide auth details
3. wait for replication to pick up all changes (usually very quick), use `INFO` or `DBSIZE` to check progress
4. stop app completely and ensure nothing is writing to any of redises
5. execute `SLAVEOF no one` to disconnect replication
6. switch `REDIS_URL` in the app to point to new server
7. start the app

## Option 2: use Redis-RIOT (harder way, where option 1 is not possible)

### General considerations:

1. Heroku uses self-signed TLS certificates, which are not verifiable. It needs special handling by setting
TLS verification to `none`, otherwise most apps are not able to connect.
Expand All @@ -9,7 +25,7 @@ TLS verification to `none`, otherwise most apps are not able to connect.

The tool that satisfies those criteria is [Redis-RIOT](https://developer.redis.com/riot/riot-redis/index.html)

**Heroku Redis:**
### Heroku Redis:

As Redis-RIOT says, master redis should have keyspace-notifications set to `KA` to be able to do live replication.
To do that:
Expand All @@ -23,7 +39,7 @@ Connect to heroku Redis CLI:
heroku redis:cli -a my-app
```

**Control Plane Redis:**
### Control Plane Redis:

Connect to Control Plane Redis CLI:

Expand All @@ -36,10 +52,10 @@ apt-get update
apt-get install redis -y

# connect to local cloud Redis
redis-cli -u MY_CONTROL_PLANE_REDIS_URL
redis-cli -u MY_CONTROL_PLANE_REDIS_URL -p 6379
```

**Useful Redis CLI commands:**
### Useful Redis CLI commands:

Quick-check keys qty:
```
Expand All @@ -49,7 +65,7 @@ info keyspace
db0:keys=9496,expires=2941,avg_ttl=77670114535
```

**Create a Control Plane sync workload**
### Create a Control Plane sync workload

```
name: riot-redis
Expand All @@ -76,7 +92,7 @@ command args:
live
```

**Sync process**
### Sync process

1. open 1st terminal window with heroku redis CLI, check keys qty
2. open 2nd terminal window with controlplane redis CLI, check keys qty
Expand Down
6 changes: 3 additions & 3 deletions templates/memcached.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ spec:
type: standard
containers:
- name: memcached
cpu: 3m
memory: 10Mi
cpu: 25m
memory: 32Mi
args:
- "-l"
- 0.0.0.0
Expand All @@ -15,7 +15,7 @@ spec:
protocol: tcp
defaultOptions:
autoscaling:
metric: latency
metric: disabled
minScale: 1
maxScale: 1
capacityAI: false
Expand Down
2 changes: 1 addition & 1 deletion templates/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
uri: "scratch://postgres-vol"
defaultOptions:
autoscaling:
metric: latency
metric: disabled
minScale: 1
maxScale: 1
capacityAI: false
Expand Down
4 changes: 2 additions & 2 deletions templates/redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ spec:
type: standard
containers:
- name: redis
cpu: 3m
memory: 20Mi
cpu: 25m
memory: 32Mi
image: "redis:latest"
ports:
- number: 6379
Expand Down
37 changes: 37 additions & 0 deletions templates/redis2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
kind: volumeset
name: redis-data
spec:
fileSystemType: ext4
initialCapacity: 10
performanceClass: general-purpose-ssd
---
kind: workload
name: redis2
spec:
type: stateful
containers:
- name: redis
args:
- '--appendonly'
- 'yes'
- '--maxmemory'
- 25mb
cpu: 25m
memory: 32Mi
image: "redis:latest"
ports:
- number: 6379
protocol: tcp
volumes:
- path: /data
recoveryPolicy: retain
uri: cpln://volumeset/redis-data
defaultOptions:
autoscaling:
metric: disabled
minScale: 1
maxScale: 1
capacityAI: false
firewallConfig:
internal:
inboundAllowType: same-gvc

0 comments on commit 9cd7951

Please sign in to comment.