一、单机配置

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. dataGridView的使用经验

    1.dataGridView是dataGrid的替代品,包含了dataGrid的全部功能. 2.为dataGridView赋值,一般将其数据设置为一个DataTabel.例子如下: DataTable ...

  2. L143 Seasonal 'Plague' Hits College Freshman

    Sometimes, all the hand sanitizer in the world cannot prevent the inevitable.College freshmen across ...

  3. C#中upd分包与发送,已经实现全部代码

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Tool ...

  4. auto_ptr, unique_ptr, shared_ptr and weak_ptr智能指针讲解

    笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...

  5. ng $scope与$rootScope的关系

    $scope与$rootScope的关系:①不同的控制器之间 是无法直接共享数据②$scope是$rootScope的子作用域对象$scope的id是随着控制器的加载顺序依次递增,$rootScope ...

  6. 第一章 Linux系统入门

    设定目标,寻求方法,勤奋努力,坚持不懈. ------你们知道了,而我们做到了.------ 世界上第一台计算机:ENIAC(埃尼亚克).1946-2 宾夕法尼亚大学. 约翰·冯·诺依曼体系 电脑的组 ...

  7. DotNet Core Console 程序使用NLog

    参考:https://github.com/NLog/NLog/wiki/Tutorial 步骤: 1. 使用Nuget安装NLog.Extensions.Logging Install-Packag ...

  8. test20181219(期末考试)

    Written with StackEdit. \(noip\)爆炸后就好久没考试了...结果今天又被抓去,感觉很慌啊... 考完了.过来填坑. T1 Description 使得\(x^x\)达到或 ...

  9. 数据库连接配置 app.config web.config

    通过ADO.Net连接程序和SQLServer数据库的连接字符串: connectionString ="server=(local);database=Demo;integrated se ...

  10. fn project 运行时配置选项

    Env Variables Description Default values DB_URL The database URL to use in URL format. SeeDatabases  ...