Docker installs redis, redis cli test connection and python API test connection.

Time:2020-10-20

Docker installing redis

Pull image, start

Pull image

docker pull redis

View existing image

docker images

Start docker

docker run -itd --name redis -p 6379:6379 redis

View the container status of docker running

docker ps

Test use

Test the connection inside the container

docker exec -it redis /bin/bash

After entering the container

[email protected]:/data# redis-cli
127.0.0.1:6379> set username jabin
OK
127.0.0.1:6379> get username
"jabin"
127.0.0.1:6379>

Test the connection outside the container

The redis container is bound to the6379Therefore, it can be considered that redis is running on the6379Port.

Using redis cli connection

If the host computer is installed withredis-cli, you can use theredis-cliTest.

➜  Desktop redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> get username
"jabin"
127.0.0.1:6379>

Using Python API connection

import redis

r = redis.StrictRedis(host='127.0.0.1', port=6379)

print(str(r.get("username"), encoding="utf-8"))

output

jabin