docker中添加redis & 在程序中应用
PS C:\Users\**> docker pull redis:latest #拉取redis镜像 latest: Pulling from library/redis bc51dd8edc1b: Pull complete 37d80eb324ee: Pull complete 392b7748dfaf: Pull complete 48df82c3534d: Pull complete 2ec2bb0b4b0e: Pull complete 1302bce0b2cb: Pull complete Digest: sha256:7b84b346c01e5a8d204a5bb30d4521bcc3a8535bbf90c660b8595fad248eae82 Status: Downloaded newer image for redis:latest docker.io/library/redis:latest PS C:\Users\**> PS D:\***> docker run --name some-redis4 -p 6379:6379 -d redis:latest #根据需求是否要设置auth,此例中没有设置 8d24fb34514077b7d57114ed47523be427ffe6623a6bac01a9e11ed3cadac297 PS D:\***> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8d24fb345140 redis:latest "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0.0.0:6379->6379/tcp some-redis4 523339a01ce4 redis:latest "docker-entrypoint.s…" 42 minutes ago Up 42 minutes 0.0.0.0:6380->6379/tcp some-redis1 PS D:\WestWin\Projects\msap\Source> docker exec -ti 8d24fb345140 /bin/bash #进入docker root@8d24fb345140:/data# redis-cli -h 127.0.0.1 -p 6379 #运行client 127.0.0.1:6379> keys * #获取key 1) "****-WebSite-dev:*****-alpha:136***-6767-8c39-756e-2*****4a4f" 2) "DataProtection-Keys" 127.0.0.1:6379> ping #验证redis server是否在运行 PONG 127.0.0.1:6379> type ****-WebSite-dev:*****-alpha:136***-6767-8c39-756e-2*****4a4f hash 127.0.0.1:6379> type DataProtection-Keys #获取key的类型 list 127.0.0.1:6379> LLEN DataProtection-Keys #获取长度 (integer) 13 127.0.0.1:6379> LRANGE DataProtection-Keys 0 1 #获取值 1) "<key id=\"*********************></key>" 127.0.0.1:6379> 127.0.0.1:6379> RPUSH testpan test1 test2 (integer) 2 127.0.0.1:6379> LRANGE testpan 0 2 1) "test1" 2) "test2" 127.0.0.1:6379> 127.0.0.1:6379> keys * #获取所有key 1) "testpan" 2) "****-WebSite-dev:****-alpha:13*****14a4f" 3) "DataProtection-Keys" 127.0.0.1:6379> type ****-WebSite-dev:****-alpha:13*****14a4f #获取数据类型 hash 127.0.0.1:6379> HGETALL ****-WebSite-dev:****-alpha:13*****14a4f #获取key & value 1) "data" 2) "\x02\x00\x0“ 3) "sldexp" 4) "720000000000" 5) "absexp" 6) "-1" 127.0.0.1:6379> HKEYS ****-WebSite-dev:****-alpha:13*****14a4f #获取key 1) "data" 2) "sldexp" 3) "absexp" 127.0.0.1:6379>
项目中使用redis的配置:
"RedisCacheServer": "127.0.0.1:6379,abortConnect=False",