30
loading...
This website collects cookies to deliver better user experience
In this chapter, i'll walk you through the installation, configuration and how to use Redis in a simple way. In this process, i'll use Docker to create a container with the Redis image.
In this first step, you need to install Docker on your machine by following the steps below.
sudo apt-get update
apt
use packages over HTTPS:sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
APT
:sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker ${USER}
run
command will search the internet and download it to your host (which is your local machine) and automatically create a container. The --name
command allows you to name the container. The -p
command maps port 6379 on the container (right side) to port 6379 on the host (left side). The -d
command runs the container in the background. The last command is the name of the image it should fetch from the remote repository redis
.docker ps
command lists all containers that are active, and you should have found something like this:CONTAINER ID| IMAGE| COMMAND| CREATED| STATUS| PORTS| NAMES
763fa8c3e7ca| redis| "docker-entrypoint.s…"| 2 hours ago| Up 2 hours| 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp| redis-tutorial
Well, now that we have a container running in the background and we know its name, we need to go in, after all, the container is a separate process from the operating system and if we want to run things in there, we need to tell the docker that we want it, right ?
The exec
command executes something inside the container and there are several modes and types of commands for this, but for now, let's just go into the container! Run:
docker exec -it redis-tutorial bash
exec
allows you to execute commands in the container without the need to be inside it. -it
is a way to associate your terminal and interact with the container. bash
will cause us to enter the container's BASH.redis-cli
.
hmset student:xxx id 1 college nnn address xn
. If the return is OK
, it means everything is fine and you can now play with Redis :)