springboot整合redis单机及集群
一、单机配置
properties配置
#单机redis
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.password=redis
启动类加
@EnableCaching
具体的方法上加
@Cacheable(value="userList")
这样的话,redis 中key值即为userList,value 为方法的返回值。pojo可能会需要序列化。
二、集群配置
properties配置
#集群redis节点以及端口
#spring.redis.cluster.nodes=192.168.1.127:7550,192.168.1.127:7551,192.168.1.127:7552,192.168.1.127:7553
RedisClusterConfig
package com.dc.sb.web.redis; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster; import java.util.HashSet;
import java.util.Set; /**
* redis 集群配置类
* 需要时直接 @Autowired JedisCluster
* @author DUCHONG
* @since 2018-12-17 17:28
**/
@Configuration
public class RedisClusterConfig { @Value("spring.redis.cluster.nodes")
private String redisNodes; @Bean
public JedisCluster getJedisCluster(){ Set<HostAndPort> nodes=new HashSet<HostAndPort>() ; String [] redisnodes=redisNodes.split(",");
for (String redisnode : redisnodes) { String [] arr=redisnode.split(":");
HostAndPort hostAndPort=new HostAndPort(arr[0],Integer.parseInt(arr[1]));
nodes.add(hostAndPort);
} return new JedisCluster(nodes);
}
}
使用时直接
@Autowired
private JedisCluster jedisCluster
springboot整合redis单机及集群的更多相关文章
- Redis学习笔记之Redis单机,伪集群,Sentinel主从复制的安装和配置
0x00 Redis简介 Redis是一款开源的.高性能的键-值存储(key-value store).它常被称作是一款数据结构服务器(data structure server). Redis的键值 ...
- spring + spring-data-redist + Redis 单机、集群(cluster模式,哨兵模式)
一.单机redis配置 1. 配置redis连接池 <bean id="jedisPoolConfig" class="redis.clients.jedis.Je ...
- Spring Boot(十三):整合Redis哨兵,集群模式实践
前面的两篇文章(Redis的持久化方案, 一文掌握Redis的三种集群方案)分别介绍了Redis的持久化与集群方案 -- 包括主从复制模式.哨兵模式.Cluster模式,其中主从复制模式由于不能自动做 ...
- Redis单机和集群配置(版本在5.0后)
摘抄并用于自己后查 单机版的配置: 1. 下载redis压缩包,然后解压缩文件(tar xzf): 2. 进入解压后的redis文件目录,编译redis源文件(make,没有c环境要gcc): 3. ...
- 在linux安装redis单机和集群后,如何在windows上使用redis客户端或者java代码访问错误的原因很简单,就是没有连接上redis服务,由于redis采用的安全策略,默认会只准许本地访问。需要通过简单配置,完成允许外网访问。
这几天在学习在linux上搭建服务器的工作,可谓历经艰辛.可喜最后收获也不少. 这次是在linux上搭建redis服务器后从windows上缺无法访问,连接不上. 仔细回忆以前搭建nginx和ftp的 ...
- redis单机及其集群的搭建
http://www.cnblogs.com/mouseIT/p/5288204.html
- SpringBoot整合Redis集群
一.环境搭建 Redis集群环境搭建:https://www.cnblogs.com/zwcry/p/9174233.html 二.Spring整合Redis集群 1.pom.xml <proj ...
- springboot+shiro+redis(单机redis版)整合教程-续(添加动态角色权限控制)
相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(单机redis版)整合教程 3. springboot+shiro+redis(集群re ...
- springboot+shiro+redis(单机redis版)整合教程
相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(集群redis版)整合教程 3.springboot+shiro+redis(单机red ...
随机推荐
- js的作用是临时修改 表单Action提交的地址,因为 又有新的动作需要把表单参数提交到 新的servlet中,这点很重要
JavaScript可以临时修稿 form表单的提交地址
- JavaScript JSON.parse()和JSON.stringify()
parse用于从一个字符串中解析出json对象,如 var str = '{"name":"huangxiaojian","age":&qu ...
- pg_buffercache
查看缓冲区缓存的内容: create extension pg_buffercache; select c.relname, count(1) as buffers from pg_class c j ...
- Oracle回收站 使用
查询回收站 SELECT * FROM RECYCLEBIN; SELECT * FROM USER_RECYCLEBIN; --USER_RECYCLEBING与RECYCLEBIN是同义词,字段完 ...
- BZOJ - 4771 七彩树 (可持久化线段树合并)
题目链接 对每个结点建立两棵线段树,一棵记录该结点的子树下每种颜色对应的最小深度,另一棵记录子树下的每个深度有多少结点(每种颜色的结点只保留最浅的深度即可),自底而上令父节点继承子结点的线段树,如果合 ...
- 配置文件Struts.xml 中type属性 redirect,redirectAction,chain的区别
1.redirect:action处理完后重定向到一个视图资源(如:jsp页面),请求参数全部丢失,action处理结果也全部丢失. 2.redirectAction:action处理完后重定向到一 ...
- Linq:从List列表中查询数据(Where查询)
获取List<Customer> customerList的函数见:http://www.cnblogs.com/yf2011/p/3369927.html 输出List中Berlin城市 ...
- imageView添加阴影和边框
注意:大量设置阴影会造成卡顿!!! 用上这句之后流畅度大大增加:imageV.layer.shouldRasterize = YES; 例: // 设置阴影 imageV.layer.shadowOf ...
- LeetCode Construct Binary Tree from String
原题链接在这里:https://leetcode.com/problems/construct-binary-tree-from-string/description/ 题目: You need to ...
- 在web.config中配置httpHandlers节点是的说明
<system.web> <httpHandlers> <add verb="*" path="*.lcj" type=" ...