Wiki > Redis
Introduction
Redis is an open source, networked, in memory key-value cache and store. It is designed to be lightweight and lightning quick. It can be used as a data structure store for an application or a cache. More information about Redis and its commands can be found at Redis.io
This guide hopes to cover the installation of the Redis Server and Client on your slot.
Installation
-
Connect to your slot through SSH
-
Create the installation directory for Redis
mkdir ~/.config/redis
-
Download the Redis source
wget http://download.redis.io/redis-stable.tar.gz
-
Extract the source and enter the directory
tar -zxf redis-stable.tar.gz; cd redis-stable
-
Compile the source
make
-
Run the recommend test on the build
make test
-
If the build passes, install it in the location we made earlier
make PREFIX=~/.config/redis/ install
-
Add the following line to
~/.bashrc
to add the executable to your PATH environment variable. This will allow you to simply typeredis-server
to use the server andredis-cli
to use the client.export PATH=${PATH}:~/.config/redis/bin/
-
Reload your
~/.bashrc
to be able to use the newly added commands.source ~/.bashrc
-
(Optional) Clean up the setup files
cd .. rm -rf redis-stable redis-stable.tar.gz
Redis server and client should now be installed in ~/.config/redis/
. The next part shall detail how to configure it.
Configuration
This section will cover the configuration of the Redis server.
A random port number between 10000 and 32767 is needed and will be used by the Redis server to bind to. The port number 18119
has automatically been generated and will be used throughout this article, but can be changed if needed.
-
Change directory to your Redis installation directory
cd ~/.config/redis/
-
Download the default configuration file
wget http://download.redis.io/redis-stable/redis.conf
-
Change the default port number in
redis.conf
to18119
port 6379
to
port 18119
-
(Optional) Uncomment the default bind address in
redis.conf
so that the Redis server will only bind to 127.0.0.1# bind 127.0.0.1
to
bind 127.0.0.1
-
(Optional) Set a password in
redis.conf
so that the Redis server requires a password before use# requirepass foobared
to
requirepass yourpassword
Warning: since Redis is pretty fast an outside user can try up to 150k passwords per second against a good box. This means that you should use a very strong password otherwise it will be very easy to break.
The Redis server should now be configured. The next section will cover how to run the server and send commands to it.
Use
This section will cover running the Redis server and sending commands to it with the Redis client.
-
Create a new screen session for our Redis server
screen -S redis
-
Start the server, using the configuration file we created and modified
redis-server ~/.config/redis/redis.conf
-
With the server running, detach from the screen session by pressing the following keys
Ctrl + A , d
More information about Screen can be found here
-
Connect to the Redis server with the Redis client. Note we have specified the port we set in the configuration file.
redis-cli -p 18119
We should now be connected to the Redis server.
You should see the following prompt on your screen: 127.0.0.1:18119>
. This shows the IP address and port of the Redis server we have currently connected to.
If you set the requirepass
setting in the configuration file, type in the following to authenticate and allow you to interact with the Redis server:
127.0.0.1:18119> AUTH yourpassword
If this was successful, the Redis server should return OK
to you. If the password was incorrect, (error) ERR invalid password
will be returned.
Now that we have connected and authenticated, we can now start issuing commands.
The following is an example for setting a key and then returning it.
127.0.0.1:18119> SET foo "bar"
OK
This will set the value of foo
to bar
. We can get this value back by issuing the command:
127.0.0.1:18119> GET foo
"bar"
And it should return "bar"
back to us.
Conclusion
This concludes the guide on how to install, configure and use the Redis server and client on your slot.
All of the commands and their uses can be found here