vmacwrites
Published in

vmacwrites

Securely Connect to Redis and Utilize Benchmark Tools

Learn how to create an encrypted connection to redis-cli using a utility like Stunnel, and benchmark your Redis instance on IBM Cloud using redis-benchmark commands.

Redis client to server encryption using stunnel

Redis (short for REmote DIctionary Server) is an open-source, in-memory data structure widely used as a cache or a database. Due to its in-memory nature that persists on disk, Redis is fast, reliable and highly performant. To learn more about Redis and its features, refer to our article “ Redis Explained.”

There are many CLI tools for Redis. The ones most commonly used are redis-cli, iredis and redli. Redis-cli is the recommended CLI.

Along with the CLI, Redis provides a benchmarking utility called redis-benchmark that that simulates X clients sending Y queries to the Redis instance on IBM Cloud:

redis-benchmark CLI commands

Before you begin

Rediss vs. Redis

Once you have provisioned the Databases for Redis instance on IBM Cloud, perform the following steps:

  1. Navigate to the Overview page of the service instance.
  2. Under Endpoints, click on the Redis tab.
  3. You should see rediss in the Endpoint:
Databases for Redis on IBM Cloud

So, what does the additional S stand for in Rediss? Similar to the ‘S’ in HTTPS, the additional s stands for secure. All the TLS/SSL-enabled connections have a rediss: prefix, whereas the unencrypted connections have a redis: prefix.

Securely connect and run commands

You need a stunnel.conf file to set up the required Stunnel configuration. As part of the conf file, you need a TLS certificate ( cert.crt):

  1. From the Overview page of the Redis service, save the TLS certificate as shown in the image above into a file called cert.crton your machine.
  2. Click on Service credentials and then on New credential > Add.
  3. On your machine, create a filecalled stunnel.conf with the contents shown below. You can find the <HOSTNAME> and the <PORT> from the service credential you created above:
[redis-cli] 
client=yes
accept=127.0.0.1:6379
connect=<HOSTNAME>:<PORT>
verify=2
checkHost=<HOSTNAME>
CAfile=/PATH/TO/cert.crt

The following is an example stunnel.conf file for your reference:

stunnel configuration file

4. From your terminal or command prompt, use the following command to run Stunnel:

stunnel stunnel.conf

5. After successful initialization, you can run any redis-cli or redis-benchmark commands. You can find the <USERNAME> and <PASSWORD> under the service credential of your Redis service. For example, to run 10,000 queries and 100 clients, you can issue the following command:

redis-benchmark -q -n 10000 -p 6379 — user <USERNAME> -a <PASSWORD> -c 100

There are many pre-built and custom commands available in the redis-benchmark utility to test your Redis server.

Conclusion

In this post, you learned how to securely connect your Redis client to the IBM Cloud Databases for Redis instance on IBM Cloud using the TLS certificate via Stunnel proxy.

What’s next?

IBM Cloud Monitoring

If you have any queries, feel free to reach out to me on Twitter or LinkedIn.

Originally published at https://www.ibm.com on April 27, 2022.

--

--

Tech writings by Vidyasagar Machupalli

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
Vidyasagar Machupalli

Vidyasagar Machupalli

Developer, IBMer, Speaker, Blogger, Teetotaller, Geek & many more…