How to work with redis for test automation

Redis is an in-memory data structure store which can be used as a database cache and supports different data types, most notably a simple key, value pair (aka dict), lists, etc.

It could be used for any relevant purpose within your test automation framework, for instance, one of the use cases that I found helpful was that we could use it as a cache of temporary auth information for test user accounts, which could be retrieved by tests running in parallel and avoid calling the actual auth APIs every time, Thus cutting a few external dependencies and making your tests faster.

Redis provides a server and a CLI interface if you want to play with the data and a bunch of client libraries for different programming languages to use them in your solution

In this post, we would see how to set up redis on an existing Ubuntu VM and how to interact with it for a very simple use case via redis-cli and then see what a simple kotlin file could look like to have an abstraction over this.

Installation and setup of redis server on an Ubuntu VM


  • Ensure you have ubuntu already setup on your machine or have a VM created.
sudo apt update 
sudo apt install build-essential
gcc --version

Install Redis via sudo apt

sudo apt update 
sudo apt install redis-server

Expose the redis server to outside the VM

By default, redis would start running on localhost ( , however, if you want to use it for your use cases, you would need to update the IP which it binds to in redis.conf file

Open the file in your comfortable editor of choice

sudo vim /etc/redis/redis.conf

Inside redis.conf file, update




Restart redis service

sudo systemctl restart redis.service

Once done, check if the redis service is running

sudo systemctl status redis

You should see an output like below:

redis-server.service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled) Active: active (running) since ... ;machines_local_timezone...;; 4min 15s ago ......

Note: I have intentionally removed some part of this output as it held sensitive information, However, you should see details around your VM/machines hostname and CPU/memory stats for your current redis instance.

Cool, 🥳 with this we have already set up a redis server on Ubuntu.

🤾🏻‍♂️ Play with redis-cli

To open redis-cli just type below


We can create a dummy key and set its value via the set command and get its value.> set "test-key" "test-value" 
OK> get "test-key"

And that’s it.

If you want to connect to this from your local machine or runner, enter below command (provided you have redis-cli already setup)

redis-cli -h host_name_or_ip -p 6379

How do we interact with this in our automation code?

Redis supports multiple clients to interact with the redis server. In the below example, we have chosen to use, however, based on your needs you could go with any other client as well.

Add below line in your build.gradle file

compile group: 'redis.clients', name: 'jedis', version: '2.9.0'

In below class, we create a class RedisHandler which accepts a host and port (where your redis server is running) and then has simple get(key) and put(key, value) methods to work with redis (quite similar to how we used the cli above)

Simple Kotlin file with abstraction over Jedis (JVM support library for redis)

And that’s a wrap 🥳. Hopefully, you would find creative use cases to use redis augment your automated tests. If you found this useful, do share it with a friend or colleague. Until next time. Happy testing and automating!

Related articles

Further read on Redis, its data types and cli utility:

Test/Automation lead at Gojek and ❤️’s code in Kotlin, Python, and Java to write scalable frameworks and utilities. Always on the lookout for hard testing problems. He writes about his adventures as a tester at ✍🏻 View all posts by Gaurav

Originally published at on May 30, 2020.

Manager SDET at Gojek, Bengaluru, I ❤️ to build scalable test automation frameworks and teams. Blog at 🇮🇳

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store