一、单机配置

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单机及集群的更多相关文章

  1. Redis学习笔记之Redis单机,伪集群,Sentinel主从复制的安装和配置

    0x00 Redis简介 Redis是一款开源的.高性能的键-值存储(key-value store).它常被称作是一款数据结构服务器(data structure server). Redis的键值 ...

  2. spring + spring-data-redist + Redis 单机、集群(cluster模式,哨兵模式)

    一.单机redis配置 1. 配置redis连接池 <bean id="jedisPoolConfig" class="redis.clients.jedis.Je ...

  3. Spring Boot(十三):整合Redis哨兵,集群模式实践

    前面的两篇文章(Redis的持久化方案, 一文掌握Redis的三种集群方案)分别介绍了Redis的持久化与集群方案 -- 包括主从复制模式.哨兵模式.Cluster模式,其中主从复制模式由于不能自动做 ...

  4. Redis单机和集群配置(版本在5.0后)

    摘抄并用于自己后查 单机版的配置: 1. 下载redis压缩包,然后解压缩文件(tar xzf): 2. 进入解压后的redis文件目录,编译redis源文件(make,没有c环境要gcc): 3. ...

  5. 在linux安装redis单机和集群后,如何在windows上使用redis客户端或者java代码访问错误的原因很简单,就是没有连接上redis服务,由于redis采用的安全策略,默认会只准许本地访问。需要通过简单配置,完成允许外网访问。

    这几天在学习在linux上搭建服务器的工作,可谓历经艰辛.可喜最后收获也不少. 这次是在linux上搭建redis服务器后从windows上缺无法访问,连接不上. 仔细回忆以前搭建nginx和ftp的 ...

  6. redis单机及其集群的搭建

    http://www.cnblogs.com/mouseIT/p/5288204.html

  7. SpringBoot整合Redis集群

    一.环境搭建 Redis集群环境搭建:https://www.cnblogs.com/zwcry/p/9174233.html 二.Spring整合Redis集群 1.pom.xml <proj ...

  8. springboot+shiro+redis(单机redis版)整合教程-续(添加动态角色权限控制)

    相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(单机redis版)整合教程 3. springboot+shiro+redis(集群re ...

  9. springboot+shiro+redis(单机redis版)整合教程

    相关教程: 1. springboot+shiro整合教程 2. springboot+shiro+redis(集群redis版)整合教程 3.springboot+shiro+redis(单机red ...

随机推荐

  1. MySQL学习笔记2018-02-07更新

    前言:本人wechat:YWNlODAyMzU5MTEzMTQ=. 如果内容有错,请指出来. win10下安装 https://dev.mysql.com/downloads/mysql/下载并解压m ...

  2. PostgreSQL 日常SQL记录

    平时用的比较多的SQL语句,有时候会忘掉一点点,在这里记录一下: 1.创建表的同时,插入数据: create table test as select generate_series(1, 10000 ...

  3. Leetcode 1019. Next Greater Node In Linked List

    单调栈的应用. class Solution: def nextLargerNodes(self, head: ListNode) -> List[int]: stack = [] ret = ...

  4. Leetcode 1005. Maximize Sum Of Array After K Negations

    class Solution(object): def largestSumAfterKNegations(self, A, K): """ :type A: List[ ...

  5. ng 通过factory方法来创建一个心跳服务

    <!DOCTYPE html> <html ng-app="myApp"> <head lang="en"> <met ...

  6. Manual Install Cocos2d-x vc template on Windows 7

    Manual Installation Process Download the template file from HERE and extract it. Open the file CCApp ...

  7. 设置eclipse显示代码错误提示的

    http://jingyan.baidu.com/article/f3e34a128d79aff5ea65356c.html

  8. POJ 2954 Triangle (pick 定理)

    题目大意:给出三个点的坐标,问在这三个点坐标里面的整数坐标点有多少个(不包含边上的) 匹克定理:I = (A-E) / 2 + 1; A: 表示多边形面积 I : 表示多边形内部的点的个数 E: 表示 ...

  9. HTTP浅析

    引言 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1. ...

  10. 【JavsScript高级程序设计】学习笔记[1]

    1. 在HTML中使用javascript 在使用script嵌入脚本时,脚本内容不能包含'</script>'字符串(会被认为是结束的标志).可以通过转义字符解决('\') 默认scri ...