custom redis action
Here’s a quick walkthru on how to create a Redis docker image that spawns containers preloaded with custom data.
Step 1: Prepare data for mass insertion into Redis
Prepare raw data for mass insertion into Redis using the Redis Protocol.
See my previous post about how to generate Redis protocol
To follow this example, save the Redis seed file to your local filesystem as data/MY_DATA.txt
Step 2: Pipe data into Redis
Start Redis Docker container
copy local data file to /data
directory inside running container
start a bash session inside the Redis container and run the mass insertion command
note: by default the container places our session in the desired ‘/data’ path *
Now our data has been loaded into Redis! It will persist until this container is destroyed. But let’s take it a bit further.
Step 3: Export database to local file system
Redis offers a quick and easy way to export this newly created database. from the Redis docs:
By default Redis saves snapshots of the dataset on disk, in a binary file called dump.rdb.
To start, exit
the bash session in the Redis container
then copy the special Redis snapshot file (dump.rdb
) to local file system.
Step 4: Create a custom Resis Docker image
with the Redis database preloaded.
in your Dockerfile
:
When containers spin up, they will automatically load the data in their dump
file and be ready to go.
Step 5: Check the work
- destroy previous container
- build new image
- run container based on new image
Check your work. Open a redis-cli
session inside your container and query your data using standard Redis commands
SHIP IT!