Redis*

In this tutorial, you’ll install Redis and launch a Redis-server on Clear Linux* OS. We invite you to pull our Clear Linux Redis instance on Docker Hub* for application or infrastructure development.

Description

Redis is an in-memory key:value store designed for quick lookups, accessible over a network. While the redis data structure store can serve as a NoSQL database for a web application, it’s also easy to integrate into an existing stack. For example, you could use the Redis caching layer for real-time responses on a leaderboard in a gaming app. Redis offers many client libraries with language-specific bindings for Python*, Perl*, Ruby, and more.

Install the Redis bundle

  1. Log in as a user with administrative privilege.

  2. Open a terminal.

  3. Update your Clear Linux OS to the latest version.

    sudo swupd update
    
  4. Install the redis-native bundle.

    sudo swupd bundle-add redis-native
    

Start the Redis-server

A systemd service unit is available to control the Redis-server. By default, Redis runs on port 6379.

  1. Start the service and set it to start automatically on boot.

    sudo systemctl enable --now redis
    
  2. Confirm the service is running.

    sudo systemctl status redis
    
  3. Verify that the Redis-server sends a reply.

    redis-cli ping
    

    Expected output:

    PONG
    

Note

If you wish to customize settings for Redis, copy the default /usr/share/defaults/etc/redis.conf file into the /etc/ directory, make changes as needed, and restart the service.

sudo cp -v /usr/share/defaults/etc/redis.conf /etc/

The Redis-server is now ready to use on Clear Linux OS. Try some of the examples shown below.

Example 1: Use the redis-cli and commands

One advantage of Redis over other NoSQL databases is that developers can easily access data structures like lists, sets, sorted sets, strings, and hashes using collection operations commands similar to those found in many programming languages. These exercises are inspired by try redis io.

After your Redis-server is running, try some basic commands.

  1. Start redis-cli. It provides syntax suggestions as you type.

    redis-cli
    
  2. SET a key to hold a string value. In the set, create connections and increment.

    SET server:name "clearlinux"
    
    MGET server:name
    

    Note

    If the key does not exist or hold a key value, nil is returned.

    SET connections 100
    
    INCR connections
    
    INCR connections
    
    DEL connections
    
  3. Create a friends list and insert new values at the end of the list.

    RPUSH friends "Deb"
    
    RPUSH friends "David"
    
    RPUSH friends "Mary"
    
  4. Modify the friends list, using a common slice method with a 0-index.

    LRANGE friends 0 1
    
    LLEN friends
    
    LPOP friends
    
    RPOP friends
    
    LLEN friends
    
  5. Consider using a hash, which maps string fields and string values, and offers multiple lookup methods.

    Enter many user key:values with HMSET. Then try HGET and HGETALL.

    HMSET user:1000 name "Robert Noyce" password "SuperEngi9eer" email "robert.noyce@intel.com"
    
    HGET user:1000 name
    
    HGET user:1000 email
    
    HGETALL user:1000
    

Example 2: Run the Clear Linux OS Redis Docker* image

We also provide a Clear Linux Redis instance, which is updated continuously and maintained by Clear Linux OS development.

sudo swupd bundle-add containers-basic
sudo systemctl start docker
sudo -E docker pull clearlinux/redis

Next Steps