Docker安装Redis
查找Redis
bash
docker search Redis
完整结果
bash
PS C:\Users\cheng> docker search Redis
NAME DESCRIPTION STARS OFFICIAL
redis Redis is an open source key-value store that... 12814 [OK]
redislabs/redisearch Redis With the RedisSearch module pre-loaded... 64
redislabs/redisinsight RedisInsight - The GUI for Redis 102
redis/redis-stack-server redis-stack-server installs a Redis server w... 76
redis/redis-stack redis-stack installs a Redis server with add... 106
redislabs/rebloom A probablistic datatypes module for Redis 27
redislabs/redis Clustered in-memory database engine compatib... 40
redislabs/rejson RedisJSON - Enhanced JSON data type processi... 53
redislabs/redismod An automated build of redismod - latest Redi... 47
redislabs/redisgraph A graph database module for Redis 27
redislabs/redistimeseries A time series database module for Redis 12
redislabs/operator 7
redislabs/operator-internal This repository contains pre-released versio... 1
拉取 Redis(最新版本)
bash
docker pull redis:latest
查看镜像列表
bash
docker images
完整结果
bash
PS C:\Users\cheng> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 9509c4dd19fb 5 weeks ago 116MB
运行容器
bash
docker run -itd --name redis-v1 -p 6379:6379 redis
- -p 6379:6379:映射容器服务的 6379 端口到宿主机的 6379 端口。外部可以直接通过宿主机ip:6379 访问到 Redis 的服务。
查看容器运行信息
bash
docker ps
完整结果
bash
PS C:\Users\cheng> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e74b17c983bf redis "docker-entrypoint.s..." 31 seconds ago Up 29 seconds 0.0.0.0:6379->6379/tcp redis-v1
测试Redis
执行容器
bash
docker exec -it redis-v1 /bin/bash
完整结果
bash
PS C:\Users\cheng> docker exec -it redis-v1 /bin/bash
root@e74b17c983bf:/data#
接着输入 redis-cli
完整结果
bash
PS C:\Users\cheng> docker exec -it redis-v1 /bin/bash
root@e74b17c983bf:/data# redis-cli
127.0.0.1:6379>
设置一个 key 和 value
bash
PS C:\Users\cheng> docker exec -it redis-v1 /bin/bash
root@e74b17c983bf:/data# redis-cli
127.0.0.1:6379> set test 1
OK
127.0.0.1:6379> get test
"1"
127.0.0.1:6379> set test 1a
OK
127.0.0.1:6379> get test
"1a"
127.0.0.1:6379>
Visual Studio Code 安装Redis工具
搜索 Redis
选择第一个安装
安装完成后, 重启vs code
点击Database
点击 Create Connection
创建一个新的连接
设置 名称、主机名、端口、点击保存,再点击连接
下图就是连接后的效果
当然,你也可以选择编辑他
编辑的效果