redis快速部署、集成、調優
1.部署
1.1 docker部署
參考:https://blog.csdn.net/taotao_guiwang/article/details/135508643
1.2 redis部署
- 資源見,百度網盤:https://pan.baidu.com/s/1qlabJ7m8BDm77GbDuHmbNQ?pwd=41ac
- 執行redis_install.sh,開始部署:
# 賦權,在redis_install目錄,執行:
chmod -R 777 .
# 執行
./redis_install.sh.sh
2. spring boot集成
核心代碼,IndexController.java:
package com.redis;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class IndexController {private static final Logger logger = LoggerFactory.getLogger(IndexController.class);@Autowiredprivate StringRedisTemplate stringRedisTemplate;@RequestMapping("/test")public void testSentinel() throws InterruptedException {try {stringRedisTemplate.opsForValue().set("testKey", "testValue"); //jedis.set(key,value);System.out.println("設置key:"+ "testKey");}catch (Exception e){logger.error("錯誤:", e);}}}
application.yml:
server:port: 8080spring:redis:host: 10.86.97.210port: 6379database: 0timeout: 3000password: test@123456
# sentinel: #哨兵模式
# master: mymaster #主服務器所在集群名稱
# nodes: 192.168.65.60:26379,192.168.65.60:26380,192.168.65.60:26381
# cluster:
# nodes: 192.168.50.61:8001,192.168.50.62:8002,192.168.50.63:8003,192.168.50.61:8004,192.168.50.62:8005,192.168.50.63:8006lettuce:pool:max-idle: 50min-idle: 10max-active: 100max-wait: 1000
瀏覽器訪問:
http://localhost:8080/test
控制臺打印:
redis desktop manager:
3.相關資源
百度網盤:https://pan.baidu.com/s/1qlabJ7m8BDm77GbDuHmbNQ?pwd=41ac