redis学习笔记8--spring集成redis

     2022-03-18     646

关键词:

spring配置单个redis

<dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>1.3.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.4.1</version>
        </dependency>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xmlns:redis="http://www.springframework.org/schema/redis"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
                            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-34.0.xsd     
                            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
                            http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop.xsd
                            http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
                            http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
                            http://www.springframework.org/schema/redis http://www.springframework.org/schema/redis/spring-redis-1.0.xsd">

    <!-- <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxIdle" value="300" />
        <property name="testOnBorrow" value="true" />
    </bean> -->

    <bean id="redisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="hostName" value="10.10.10.30"></property>
        <property name="port" value="6379"></property>
        <!-- 引入默认的连接池配置 -->
        <property name="usePool" value="true"></property>
        <!-- 引入自定义的poolConfig连接池配置 -->
        <!-- <property name="poolConfig" ref="poolConfig"></property> -->
    </bean>
    
    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
        <property name="connectionFactory" ref="redisConnectionFactory"></property>
    </bean>

</beans>

spring配置redis集群

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xmlns:redis="http://www.springframework.org/schema/redis"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
                            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-34.0.xsd     
                            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
                            http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop.xsd
                            http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
                            http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
                            http://www.springframework.org/schema/redis http://www.springframework.org/schema/redis/spring-redis-1.0.xsd">

    <context:annotation-config>
        <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
            <property name="maxTotal" value="1000" />
            <property name="maxIdle" value="10" />
            <property name="minIdle" value="1" />
            <property name="maxWaitMillis" value="30000" />
            <property name="testOnBorrow" value="true" />
            <property name="testOnReturn" value="true" />
            <property name="testWhileIdle" value="true" />
            <!-- <property name="testWhileIdle" value="true"/> -->
        </bean>

        <bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool"
            scope="singleton">
            <constructor-arg ref="jedisPoolConfig" />
            <constructor-arg>
                <list>
                    <bean class="redis.clients.jedis.JedisShardInfo">
                        <constructor-arg name="host" value="10.10.10.20" />
                        <constructor-arg name="port" value="6379" />
                        <constructor-arg name="auth" value="Java0713!" />
                        <constructor-arg index="2" value="instance:01"/>
                    </bean>
                    <bean class="redis.clients.jedis.JedisShardInfo">
                        <constructor-arg name="host" value="10.10.10.30" />
                        <constructor-arg name="port" value="6379" />
                        <constructor-arg name="auth" value="Java0713!" />
                        <constructor-arg index="2" value="instance:02"/>
                    </bean>
                    <bean class="redis.clients.jedis.JedisShardInfo">
                        <constructor-arg name="host" value="10.10.10.40" />
                        <constructor-arg name="port" value="6379" />
                        <constructor-arg name="auth" value="Java0713!" />
                        <constructor-arg index="2" value="instance:03"/>
                    </bean>
                </list>
            </constructor-arg>
        </bean>
        <!--java帮我们同步sentinel的信息,将主从信息同步到客户端来 -->
        <bean class="redis.clients.jedis.JedisSentinelPool">
            <constructor-arg index="0" value="mymaster" />
            <constructor-arg index="1">
                <set>
                    <value>127.0.0.1:6379</value>
                </set>
            </constructor-arg>
            <constructor-arg index="2" ref="jedisPoolConfig" />
        </bean>
    </context:annotation-config>
</beans>

 

redis学习笔记jedis(jediscluster)操作redis集群redis-cluster

...用spring-data-redis实现incr自增Redis利用Hash存储节约内存Redis学习笔记(九)redis实现时时直播列表缓存,支持分页[热点数据存储]Redis学习笔记(八)redis之lua脚本学习Redis学习笔记(七)jedis超时重试机制注意事... 查看详情

redis学习笔记

解压后的安装[[email protected]redis-3.0.5]#make指定安装目录:[[email protected]redis-3.0.5]#makePREFIX=/usr/local/redisinstall进入/usr/local/redis里面:[[email protected]redis]#lsbin[[email protecte 查看详情

redis6学习笔记(自用)(代码片段)

Redis学习笔记文章目录Redis学习笔记一、Redis概述1.1Redis安装1.2Redis相关知识介绍二、常用五大数据类型2.1Redis键(key)2.2Redis字符串(String)2.2.1简介2.2.2常用命令2.2.3数据结构2.3Redis列表(List)2.3.1简介2.3.2常用命令2.3.3数据结构2.4Redis集合(S... 查看详情

redis学习笔记之三:redis配置

 redis配置文件在其安装路径下,文件名为redis.conf(windows版的为:redis.windows.conf)。可以使用config命令查看或设置配置项1、查看配置  语法:config get config_setting_name  可以使用*获取所有配置项  举例:configge... 查看详情

redis学习笔记2

window服务端开启Linux服务端开启下载好安装包放到服务器===就可以了 查看详情

springboot集成redis(代码片段)

springboot整合Redisredis学习笔记狂神视频SpringBoot操作数据:spring-datajpajdbcmongodbredis!SpringData也是和SpringBoot齐名的项目!说明:在SpringBoot2.x之后,原来使用的jedis被替换为了lettucejedis:采用的直连 查看详情

redis学习笔记三

一、redis复制数据库复制指的是发生在不同数据库实例之间,单向的信息传播的行为,通常由被复制方和复制方组成,被复制方和复制方之间建立网络连接,复制方式通常为被复制方主动将数据发送到复制方,复制方接收到数据... 查看详情

redis学习笔记4--redis管道(pipeline)

Redis是一个cs模式的tcpserver,使用和http类似的请求响应协议。一个client可以通过一个socket连接发起多个请求命令。每个请求命令发出后client通常会阻塞并等待redis服务处理,redis处理完后请求命令后会将结果通过响应报文返回给cli... 查看详情

redis学习笔记——搭建环境

...用它做缓存。由于接下来有可能会用到,所以这里记录下学习过程。一、安装Redis1.官网地址:http://redis.io/2.windows 查看详情

ridis学习笔记

菜鸟教程官网:runoob.comRedis学习总结:Redis的下载安装:1.下载地址:下载地址:https://github.com/MSOpenTech/redis/releases。2.运行:运行解压后的redis-server.exe文件;3.测试连接:redis-cli.exe;输入ping若返回pang命令,则表示连接成功(简称... 查看详情

学习笔记——redis事务乐观锁悲观锁

2023-01-29一、redis事务与乐观锁相关命令1、redis事务(1)redis事务的含义redis事务是一个单独的隔离操作:事务中的所有命令都会序列化、按顺序执行。事务在执行过程中,不会被其他客户端送来的命令请求所打断。(2)redis事务... 查看详情

redis学习笔记2:了解redis入门

1、Redis是什么?(RemoteDictionaryServer远程字典服务)Redis是现在最受欢迎的NoSQL数据库之一,Redis是一个使用ANSIC编写的开源、包含多种数据结构、支持网络、基于内存、可选持久性的键值对存储数据库,其具备... 查看详情

redis学习笔记系列目录

...做成笔记,杂糅一些网友智慧结晶,为有缘人的学习和日后自己的复习提供材料。Redis安装、配置、启动、关闭初识Redis单线程架构数据类型:字符串(string)数据类型:哈希(hashÿ 查看详情

redis深入学习笔记clientlist命令详解

Redis的clientlist命令可以获取当前连接到redisserver端的所有客户端以及相关状态,本篇主要介绍每一个参数的作用。clisntlist命令输出结果如下:(1)标识:id、addr、fd、name这四个属性属于客户端的标识:    id:客户端连接的... 查看详情

尚硅谷redis学习笔记--redis数据类型

一、前言该技术博客是关于尚硅谷最新发布的Redis教程的笔记总结,希望能在这里分享出来,为大家带来帮助!二、NoSQL数据库简介1.技术发展技术的分类:解决功能性的问题:Java、Jsp、RDBMS、Tomcat、HTML、Linux... 查看详情

redis学习笔记(代码片段)

RedisNoSQL的四大分类NoSQL=NotOnlySQL,泛指非关系型数据库。KV键值对新浪(Redis)美团(Redis+Tair)阿里、百度(Redis+memecache)文档型数据库MongoDB——MongoDB是一个基于分布式文件存储的数据库,C++编写,主要用来处理大量的文档。MongoDB是一... 查看详情

redissentinel学习笔记

转载出处:http://blog.csdn.net/lihao21概述Redis Sentinel 是用来实现Redis高可用的一套解决方案。RedisSentinel由两个部分组成:由一个或者多个Sentinel实例组成Sentinel系统;由一个主Redis服务器(masterredis)和多个从Redis服务器(slavered... 查看详情

redis学习笔记4:redis事务(代码片段)

事务:要么同时成功,要么同时失败。--->原子性Redis事务:单条命令保证原子性,但其事务不保证。(即在整一个事务中,正确的命令依然执行,错误的不执行。)1.正常开启Redis事务步骤:... 查看详情