Setup Redis in (Much) Less Than 60 seconds!

Redis server

I have been away for some time from this blog, but that was for a reason, I got a new job at Redis (and I can’t hide I am truly enthusiastic about my new position as Technical Enablement Architect!), and taking some time to onboard and extend my knowledge of the awesome Redis server, the popular in-memory key-value storage. So my future posts will likely be about Redis and the infinite chances to “getting things done” using this very nice solution.

Maybe you know Redis as an efficient caching layer, but once you get to know it a bit more, you realize that Redis has all the qualities to be your only primary database (and especially once you discover Redis Enterprise features for a highly scalable and configurable solution).

Click here to get a free copy of “Caching at Scale With Redis”

So back to this post, do you think you can setup Redis in less than 60 seconds? I challenge you, I will offer not one, but several alternatives to have Redis in your laptop (Mac or Linux) in that time, and spare some time to connect to it! Let’s see in detail five options to have a Redis server at hand:

  • Download, compile run and test
  • Run in a Docker container
  • Using a package manager
  • Redis Cloud free database
  • Try Redis from your browser

Download, compile, run, and test

You can download, compile and run Redis on your Mac or Linux box (assuming you can indeed wget stuff from the internet, and compile C code!). This is as easy as copying this script on your terminal

SECONDS=0
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
tar xzf redis-6.2.6.tar.gz
cd redis-6.2.6
make -j4
src/redis-server &
src/redis-cli set foo bar
src/redis-cli get foo
echo "REDIS SETUP IN $SECONDS seconds :)"

Easy, isn’t it? I executed this snippet on my Mac (a 2 GHz Quad-Core Intel Core i5 machine) and this is easily done in much less than a minute, and I also have time to set a test key, and retrieve it, and drink a glass of water!

bash-3.2$ src/redis-server &
[1] 13517
bash-3.2$ src/redis-cli set foo bar
13517:C 05 Oct 2021 16:07:14.658 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13517:C 05 Oct 2021 16:07:14.659 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=13517, just started
13517:C 05 Oct 2021 16:07:14.659 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
13517:M 05 Oct 2021 16:07:14.660 * Increased maximum number of open files to 10032 (it was originally set to 256).
13517:M 05 Oct 2021 16:07:14.660 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 13517
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

13517:M 05 Oct 2021 16:07:14.662 # Server initialized
13517:M 05 Oct 2021 16:07:14.662 * Ready to accept connections
OK
bash-3.2$ src/redis-cli get foo
"bar"
bash-3.2$ echo "REDIS SETUP IN $SECONDS seconds :)"
REDIS SETUP IN 20 seconds :)

Run in a Docker container

Redis (which comes in two flavors, the open source server and the Redis Enterprise) makes both containers available at Docker hub:

That said, observe how you setup redis in a shot, and still have time to drink not one, but two glasses of water!

bash-3.2$ docker run --name redis_cnt -d redis
Unable to find image 'redis:latest' locally
latest: Pulling from library/redis
07aded7c29c6: Pull complete 
1a5d64c027a4: Pull complete 
189d72810950: Pull complete 
b85aac102f7d: Pull complete 
fe1bca69301e: Pull complete 
fd69789c2b06: Pull complete 
Digest: sha256:c98f0230b5f1831f4f5dd764c4ea8ef11d3e3a1a3593278eb952373d97c82b27
Status: Downloaded newer image for redis:latest
dd0c0df87a596dccd4abcfb020dca22042830ac30d71593efb4a42eaa22a0106
bash-3.2$ echo "REDIS DOCKER SETUP IN $SECONDS seconds :)"
REDIS DOCKER SETUP IN 12 seconds :)

You can indeed play with it from your host:

bash-3.2$ docker exec -it redis_cnt redis-cli set foo bar
OK
bash-3.2$ docker exec -it redis_cnt redis-cli get foo
"bar"

or just start a session and learn more about redis-cli:

bash-3.2$ docker exec -it redis_cnt bash
root@dd0c0df87a59:/data# redis-cli --help
redis-cli 6.2.5

Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
  -h <hostname>      Server hostname (default: 127.0.0.1).
  -p <port>          Server port (default: 6379).
  -s <socket>        Server socket (overrides hostname and port).
  -a <password>      Password to use when connecting to the server.
                     You can also use the REDISCLI_AUTH environment
                     variable to pass this password more safely
                     (if both are used, this argument takes precedence).

Using a package manager

If you are not happy with compiling or with containers, you can simply use your favorite package manager (brew, yum or apt-get and have your Redis installed in matter of seconds).

brew install redis
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> Updated Formulae
Updated 6 formulae.
==> Updated Casks
Updated 12 casks.

==> Downloading https://ghcr.io/v2/homebrew/core/redis/manifests/6.2.6
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/redis/blobs/sha256:246f73498993a2a0c6c4326a298d2fcc3da6d61904ad09a631aa9c63a6800f76
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:246f73498993a2a0c6c4326a298d2fcc3da6d61904ad09a631aa9c63a6800f76?se=2021
######################################################################## 100.0%
==> Pouring redis--6.2.6.big_sur.bottle.tar.g
...

And start as easily as running a command.

bash-3.2$ brew services start redis
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 1440, done.
remote: Counting objects: 100% (319/319), done.
remote: Compressing objects: 100% (233/233), done.
remote: Total 1440 (delta 123), reused 245 (delta 80), pack-reused 1121
Receiving objects: 100% (1440/1440), 425.26 KiB | 2.12 MiB/s, done.
Resolving deltas: 100% (600/600), done.
Tapped 1 command (35 files, 525.1KB).
==> Successfully started `redis` (label: homebrew.mxcl.redis)
bash-3.2$ ps aux | grep redis
mortensi          5148   0.0  0.0  4277640    736 s000  S+    9:12PM   0:00.00 grep redis
mortensi          5144   0.0  0.0  4314452   3456   ??  S     9:12PM   0:00.03 /usr/local/opt/redis/bin/redis-server 127.0.0.1:6379 

Redis Cloud free database

And last but not least, if you are not eager to play with things in your machine, you can always create a free Redis Cloud account here.

Maybe it won’t be a matter of seconds, but I promise it will be just a few minutes! You can get a 30MB database and a public endpoint to authenticate right away from your laptop. No VPN, no certificates setup, can’t be easier. And it’s free, forever!

Try Redis from your browser

To conclude this quick roundup, you can also try this test instance online so you can get an idea of Redis and commands by using this online test service, https://try.redis.io/. Just type HELP to discover more.

So if you don’t have a Redis up and running by now, no excuses, can’t be easier to have it at hand and start having some real fun (I promise). So at this point you can just browse official open source Redis documentation, or even have a look at Redis in Action, freely available online.

Read “Redis in Action” for free here

Have fun with Redis!

Redis is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Any use by mortensi is for referential purposes only and does not indicate any sponsorship, endorsement or affiliation between Redis and mortensi.

Leave A Comment