Redis*¶
Redis is an in-memory key:value store designed for quick lookups, accessible over the network. In this tutorial, you’ll install redis and launch a redis-server on Clear Linux OS, plus learn a few basic redis commands. We also invite you to pull our Clear Linux Redis instance on dockerhub* for application or infrastructure development.
While the redis data structure store can serve as a NoSQL database for a Web application, it’s also easy to integrate in 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.
Prerequisites¶
- Install the redis-native bundle in Clear Linux OS
- Install the containers-basic bundle in Clear Linux OS (only required in Example 2)
Install the redis bundle¶
In Clear Linux OS, find redis in the redis-native bundle.
- Open a Terminal and login as an administrative user.
- Add
redis-native
.
sudo swupd bundle-add redis-native
注解
If the bundle already exists, no action is required.
Start the redis-server¶
A systemd service unit is available to control the redis server. By default, redis runs on port 6379.
Start the service.
systemctl start redis
注解
To stop redis run systemctl stop redis.
Assure the service is running.
systemctl status redis
Verify the redis-server sends a reply.
redis-cli ping
注解
Expected output: PONG.
Optional: If you wish to apply advanced configuration, copy the redis.conf into /etc/ directory.
sudo cp /usr/share/defaults/etc/redis.conf /etc/
The redis-server is now ready to use on Clear Linux OS. Try some examples below.
Example 1: Use the redis-cli and try 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.
Enter the redis-cli. It provides syntax suggestions as you type.
redis-cli
SET key to hold string value. In the set create connections and increment.
SET server:name "clearlinux"
MGET server:name
注解
If the key does not exist or hold a key value, nil is returned.
SET connections 100
INCR connections
INCR connections
DEL connections
Create a friends list and insert new values at the end of the list.
RPUSH friends "Deb"
RPUSH friends "David"
RPUSH friends "Mary"
Modify friends list, using a common slice method with a 0-index.
LRANGE friends 0 1
LLEN friends
LPOP friends
RPOP friends
LLEN friends
Consider using a hash, a very useful data type, which maps string fields and string values, offering 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¶
- Follow the redis quickstart tutorial to expand potential uses.
- Learn to Docker*.