安装redis
官网: https://redis.io/ ,点击下载,选择docker安装会跳转到 docker中redis的网址https://hub.docker.com/_/redis/。通过配置docker-compose.yml 配置文件,来安装及启动redis。
version: '3'services:redis-test:image: 'redis'restart: alwayscontainer_name: 'redis-test'ports:- 15001:6379volumes:- /home/redistest:/datacommand: ["redis-server", "--requirepass", "123456"]
yml文件的编译需要注意其严格模式,如在: 后面需要有空格。
[root@VM_0_17_centos redistest]# docker-compose up -d
Creating network "redistest_default" with the default driver
Pulling redis-test (redis:)...
latest: Pulling from library/redis
852e50cd189d: Downloading [==> ] 1.121MB/27.11MB
76190fa64fb8: Download complete
852e50cd189d: Downloading [===> ] 1.682MB/27.11MB
852e50cd189d: Downloading [====================================> ] 17.59MB/24.38MB
6f4b2af24926: Download complete
1cf1d6922fba: Download complete
852e50cd189d: Pull complete
76190fa64fb8: Pull complete
9cbb1b61e01b: Pull complete
d048021f2aae: Pull complete
6f4b2af24926: Pull complete
1cf1d6922fba: Pull complete
Digest: sha256:5b98e32b58cdbf9f6b6f77072c4915d5ebec43912114031f37fa5fa25b032489
Status: Downloaded newer image for redis:latest
Creating redis-test ... done
[root@VM_0_17_centos redistest]#
此时,redis已安装完成
连接redis并运行命令
[root@VM_0_17_centos redistest]# docker ps | grep redis
d65ffe99bacd redis "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:15001->6379/tcp redis-test
[root@VM_0_17_centos redistest]# docker exec -it redis-test redis-cli
127.0.0.1:6379>
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379>
- docker ps | grep redis 查看容器名称 以及 运行id
- docker exec -it redis-test(容器名称或者运行id) redis-cli 来连接redis
-
redis cli
redis命令参考:http://doc.redisfans.com/
redis GUI工具
推荐 AnotherRedisDesktopManager(免费)
下载地址: https://github.com/qishibo/AnotherRedisDesktopManager/releases
-
redis 与nodejs集成
1.npm install redis npm地址:https://www.npmjs.com/package/redis
git地址:https://github.com/NodeRedis/node-redis(可用来查看如何使用以及相关配置)
