Redis in-memory storage


© Lead Image © redspruce,

© Lead Image © redspruce,

Article from Issue 219/2019

Include binary data and image files in your IoT projects with Redis, an open source, in-memory data structure store.

For many Internet of Things (IoT) projects, a message-queuing system like MQTT (message-queuing telemetry transport) is all you need to connect sensors, devices, and graphic interfaces. However, if you have requirements for high throughput or you are storing special data types (e.g., binary data or image files), you should take a look at Redis.

Redis (Remote directory server) [1] is an open source, in-memory data structure store that can be used as a database, cache, and message broker. It supports a wide range of data structures, such as strings, hashes, lists, sets, bitmaps, HyperLogLogs, and geospatial indexes. Redis servers can be loaded locally, or they are available as web-hosted solutions. Redis libraries are available for a wide variety of programming languages.

In this article, I show you how to set up a Redis system with two examples. The first is a flame scanner that connects an Arduino module to a Node-RED web dashboard. The second example is a Raspberry Pi weather station, in which a webcam image is stored in a Redis server and a PHP web page shows the data.

Getting Started Locally

To install Redis on Ubuntu systems, go to the terminal and enter:

$sudo apt-get update
$sudo apt-get install redis-server

Once Redis is installed, it can be started by:


The redis-cli command-line tool can be used for monitoring and testing; for example, to assign and read a value:

$redis-cli> set mytag1 12.3
OK> get mytag1

The default Redis security is set to local access only. To open the server to remote connections, edit the /etc/redis/redis.conf file and either comment out all the bind statements (e.g., #bind or add bind statements for all your valid IP addresses. After editing the config file, you need to restart the Redis server by entering the

sudo service redis-server restart


Redis Performance

The Redis in-memory data store boasts some incredible throughput numbers. I wanted to test this out, so I loaded Redis on an old Acer Aspire One laptop with a 1.6GHz N270 Intel Atom processor and 4GB of RAM. A Redis tool called redis-benchmark allows me to do some upfront performance analysis configured for different messages, client counts, and test durations.

For my IoT project, I wanted to check whether my low-end Ubuntu laptop could handle 10 clients. My maximum throughput for GET and SET messages can be estimated by the redis-benchmark command shown in Listing 1.

Listing 1



Although I have many performance factors to consider, for my IoT system with 10 Arduino/Pi modules, I probably won't generate more than 50 SETs/sec. According to the test, my old Ubuntu laptop appears to be able to do 5,000+ SETs/sec, so I shouldn't have any problems using it for my IoT system.

Flame Scanner Example

My goal for the flame scanner example is to monitor my fireplace remotely with an ESP8266-compatible Arduino module and a Redis server to store the data (Figure 1). A lot of IoT dashboard options are available, but I like to use Node-RED because it is 100% standalone.

Figure 1: Arduino/Redis flame scanner diagram.

For my hardware setup, I mounted a low-cost infrared (IR) flame sensor [2] ($3) on some Meccano pieces, and I aimed it at the center of the fireplace. A DHT11 temperature/humidity sensor [3] ($4) was also connected to the Arduino module to record the room temperature (Figure 2). I did my testing with a Wemos D1 module and a proto shield, but any of the ESP8266-based Arduino modules could be used.

Figure 2: Arduino/Redis flame scanner setup.

Redis supports a number of storage methods, with the most common methods being SET/GET and PUBLISH/SUBSCRIBE. For this example, I used the PUBLISH/SUBSCRIBE method to make it similar to a messaging system like MQTT.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Logstash

    When something goes wrong on a system, the logfile is the first place to look for troubleshooting clues. Logstash, a log server with built-in analysis tools, consolidates logs from many servers and even makes the data searchable.

  • Monitoring Old Devices

    Create monitoring dashboards with SSH, command-line tools, and Node-RED.

  • IoT with RabbitMQ

    Connect multiple protocols and servers together on your IoT projects.

  • Node-RED on Android

    We show you how to control devices connected to Rasp Pi GPIO pins with text messages from an Android phone.

  • WiFi Thermo-Hygrometer

    A WiFi sensor monitors indoor humidity and temperature and a Node-RED dashboard reports the results, helping you to maintain a pleasant environment.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95