`
Donald_Draper
  • 浏览: 980072 次
社区版块
存档分类
最新评论

Spring与Redis的集成详解一

阅读更多
Jedis获取Redis连接详解:http://donald-draper.iteye.com/blog/2347121
Redis的客户端Jedis及Jedis操作Redis命令详解:http://donald-draper.iteye.com/blog/2347192
在前文中我们分析了Jedis如何与Redis进行通信,Spring与Redis的集成,在Spring与Redis的集成
的文章中,有如下Redis配置:
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:p="http://www.springframework.org/schema/p" 
		   xmlns:tx="http://www.springframework.org/schema/tx"
		   xmlns:context="http://www.springframework.org/schema/context"
		   xsi:schemaLocation="
			http://www.springframework.org/schema/beans 
			http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
			http://www.springframework.org/schema/tx 
			http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
			http://www.springframework.org/schema/context
			http://www.springframework.org/schema/context/spring-context-3.0.xsd
			   ">
	
	
	<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">  
		<property name="maxIdle" value="${redis.maxIdle}" />  
		<property name="maxActive" value="${redis.maxActive}" />  
		<property name="maxWait" value="${redis.maxWait}" />  
		<property name="testOnBorrow" value="${redis.testOnBorrow}" />  
	</bean>  
	<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"  
		p:host-name="${redis.host}" 
		p:port="${redis.port}" 
		p:password="${redis.pass}"  
		p:pool-config-ref="poolConfig"/>  
	  
	<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">  
		<property name="connectionFactory"   ref="connectionFactory" />  
	</bean>	   
</beans>

这里主要有三点要说1.JedisPoolConfig,2.JedisConnectionFactory,3.StringRedisTemplate
在Jedis连接Redis详解篇中,我们有说JedisPoolConfig,今天我们就再来回顾一下,以便对Spring与Redis的集成有一个详细的了解
1.JedisPoolConfig
import org.apache.commons.pool.impl.GenericObjectPool;
public class JedisPoolConfig extends org.apache.commons.pool.impl.GenericObjectPool.Config
{
    public JedisPoolConfig()
    {
        setTestWhileIdle(true);
        setMinEvictableIdleTimeMillis(60000L);
        setTimeBetweenEvictionRunsMillis(30000L);
        setNumTestsPerEvictionRun(-1);
    }
    public int getMaxIdle()
    {
        return maxIdle;
    }
    public void setMaxIdle(int maxIdle)
    {
        this.maxIdle = maxIdle;
    }
     public int getMinIdle()
    {
        return minIdle;
    }

    public void setMinIdle(int minIdle)
    {
        this.minIdle = minIdle;
    }
      public int getMaxActive()
    {
        return maxActive;
    }
    public void setMaxActive(int maxActive)
    {
        this.maxActive = maxActive;
    }
    public long getMaxWait()
    {
        return maxWait;
    }
    public void setMaxWait(long maxWait)
    {
        this.maxWait = maxWait;
    }
...
}

从JedisPoolConfig我们可以看出,JedisPoolConfig的功能主要是配置连接最大空闲
时间,存活数量,及等待时间;
再来看GenericObjectPool.Config
public class GenericObjectPool extends BaseObjectPool
    implements ObjectPool
{
public static class Config
    {

        public int maxIdle;
        public int minIdle;//空闲时间
        public int maxActive;//存活数量
        public long maxWait;//等待时间
        public byte whenExhaustedAction;
        public boolean testOnBorrow;//在获取连接时,是否要测试连接
        public boolean testOnReturn;
        public boolean testWhileIdle;
        public long timeBetweenEvictionRunsMillis;
        public int numTestsPerEvictionRun;
        public long minEvictableIdleTimeMillis;
        public long softMinEvictableIdleTimeMillis;
        public boolean lifo;

        public Config()
        {
            maxIdle = 8;
            minIdle = 0;
            maxActive = 8;
            maxWait = -1L;
            whenExhaustedAction = 1;
            testOnBorrow = false;
            testOnReturn = false;
            testWhileIdle = false;
            timeBetweenEvictionRunsMillis = -1L;
            numTestsPerEvictionRun = 3;
            minEvictableIdleTimeMillis = 1800000L;
            softMinEvictableIdleTimeMillis = -1L;
            lifo = true;
        }
    }
}

从上可以看出JedisPoolConfig的父类Config为GenericObjectPool的静态内部类,与连接池
有关的属性在Config中,而属性的设置在JedisPoolConfig中;
再来看Jedis连接工厂
2.JedisConnectionFactory
public class JedisConnectionFactory
    implements InitializingBean, DisposableBean, RedisConnectionFactory
{
    private JedisShardInfo shardInfo;//Jedis共享信息类
    private String hostName;//ip
    private int port;//端口
    private int timeout;//超时时间
    private String password;//密码
    private boolean usePool;//是否用连接池
    private JedisPool pool;//jedis连接池
    private JedisPoolConfig poolConfig;//池配置
    private int dbIndex;//数据库
    public JedisConnectionFactory()
    {
        hostName = "localhost";
        port = 6379;
        timeout = 2000;
        usePool = true;
        pool = null;
        poolConfig = new JedisPoolConfig();
        dbIndex = 0;
    }

    public void afterPropertiesSet()
    {
        if(shardInfo == null)
        {
	    //创建JedisShardInfo,设置JedisShardInfo的属性
            shardInfo = new JedisShardInfo(hostName, port);
            if(StringUtils.hasLength(password))
                shardInfo.setPassword(password);
            if(timeout > 0)
                shardInfo.setTimeout(timeout);
        }
        if(usePool)
	    //这个我们在Jedis获取redis连接篇中有详解,初始化连接池,及Jedis连接客户端工厂
            pool = new JedisPool(poolConfig, shardInfo.getHost(), shardInfo.getPort(), shardInfo.getTimeout(), shardInfo.getPassword());
    }
}

来看JedisConnectionFactory的获取连接
    public volatile RedisConnection getConnection()
    {
        return getConnection();
    }
    public JedisConnection getConnection()
    {
        //获取连接,如果使用连接池,则直接从连接池中获取,否则直接创建一个连接
        Jedis jedis = fetchJedisConnector();
	 //返回连接
        return postProcessConnection(usePool ? new JedisConnection(jedis, pool, dbIndex) : new JedisConnection(jedis, null, dbIndex));
    }
     //获取连接,如果使用连接池,则直接从连接池中获取,否则直接创建一个连接
     protected Jedis fetchJedisConnector()
    {
         //如果使用连接池,则直接从连接池中获取
        if(usePool && pool != null)
	    
            return (Jedis)pool.getResource();
        Jedis jedis;
	//否则直接创建一个连接
        jedis = new Jedis(getShardInfo());
        jedis.connect();
        return jedis;
        Exception ex;
        ex;
        throw new DataAccessResourceFailureException("Cannot get Jedis connection", ex);
    }
    //返回连接
    protected JedisConnection postProcessConnection(JedisConnection connection)
    {
        return connection;
    }

//JedisConnection
public class JedisConnection
    implements RedisConnection
{
    private static final Field CLIENT_FIELD;
    private static final Method SEND_COMMAND;
    private static final Method GET_RESPONSE;
    private final Jedis jedis;//jedis连接
    private final Client client;//jedis与redis的socket客户端
    private final BinaryTransaction transaction;//事务
    private final Pool pool;//Jedis连接池
    private boolean broken;
    private volatile JedisSubscription subscription;
    private volatile Pipeline pipeline;//管道
    private final int dbIndex;
  public JedisConnection(Jedis jedis, Pool pool, int dbIndex)
    {
        broken = false;
        this.jedis = jedis;
        client = (Client)ReflectionUtils.getField(CLIENT_FIELD, jedis);
        transaction = new Transaction(client);
        this.pool = pool;
        this.dbIndex = dbIndex;
        if(dbIndex > 0)
            select(dbIndex);
    }
    public void openPipeline()
    {
        if(pipeline == null)
            pipeline = jedis.pipelined();
    }
}

JedisConnectionFactory在连接池配置和ip和port和密码等信息初始化后,
初始化Jedis连接池(初始化连接池及Jedis连接客户端工厂),JedisConnectionFactory获取连接的方式如果使用连接池,则直接从连接池中获取,否则直接创建一个连接JedisConnection。

再来看StringRedisTemplate
3.StringRedisTemplate
public class StringRedisTemplate extends RedisTemplate
{
    public StringRedisTemplate()
    {
        org.springframework.data.redis.serializer.RedisSerializer stringSerializer = new StringRedisSerializer();
        //设置k-v,hash k-v的序列化工具
	setKeySerializer(stringSerializer);
        setValueSerializer(stringSerializer);
        setHashKeySerializer(stringSerializer);
        setHashValueSerializer(stringSerializer);
    }
}

再来看RedisTemplate
public class RedisTemplate extends RedisAccessor
    implements RedisOperations
{
    private boolean exposeConnection;
     //k-v,hash k-v的序列化工具,在StringRedisTemplate的构造中,初始化
    private RedisSerializer defaultSerializer;
    private RedisSerializer keySerializer;
    private RedisSerializer valueSerializer;
    private RedisSerializer hashKeySerializer;
    private RedisSerializer hashValueSerializer;
    private RedisSerializer stringSerializer;
    private ValueOperations valueOps;
    private ListOperations listOps;
    private SetOperations setOps;
    private ZSetOperations zSetOps;
    public RedisTemplate()
    {
        exposeConnection = false;
        defaultSerializer = new JdkSerializationRedisSerializer();
        keySerializer = null;
        valueSerializer = null;
        hashKeySerializer = null;
        hashValueSerializer = null;
        stringSerializer = new StringRedisSerializer();
    }
}

在Spring与Redis继承中,有下面一段
@Repository(value="memberDao")
public class MemberDaoImpl extends RedisGeneratorDao<String,Member> implements MemberDao{
	/**
	 * 添加对象
	 */
	public boolean add(final Member member) {  
		boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {  
			public Boolean doInRedis(RedisConnection connection)  
					throws DataAccessException {  
				RedisSerializer<String> serializer = getRedisSerializer();  
				byte[] key  = serializer.serialize(member.getId());  
				byte[] name = serializer.serialize(member.getNickname());  
				return connection.setNX(key, name);  
			}  
		});  
		return result;  
	} 
}

上面redisTemplate实际上为Redis配置文件中的StringRedisTemplate,

我们来看下面这段
redisTemplate.execute(new RedisCallback<Boolean>() {  
    public Boolean doInRedis(RedisConnection connection)  throws DataAccessException { }  });  


//RedisTemplate
public Object execute(RedisCallback action)
    {
        return execute(action, isExposeConnection());
    }

    public Object execute(RedisCallback action, boolean exposeConnection)
    {
        return execute(action, exposeConnection, false);
    }

    public Object execute(RedisCallback action, boolean exposeConnection, boolean pipeline)
    {
        //RedisConnectionFactory
        org.springframework.data.redis.connection.RedisConnectionFactory factory;
        RedisConnection conn;//RedisConnection
        boolean existingConnection;
        boolean pipelineStatus;
        Assert.notNull(action, "Callback object must not be null");
	//获取redis连接工厂
        factory = getConnectionFactory();
	//从连接工厂获取连接
        conn = RedisConnectionUtils.getConnection(factory);
	//确定事务管理器中是否存在Redis连接工厂
        existingConnection = TransactionSynchronizationManager.hasResource(factory);
        preProcessConnection(conn, existingConnection);
        pipelineStatus = conn.isPipelined();
        if(pipeline && !pipelineStatus)
	    //打开管道
            conn.openPipeline();
        Object obj;
	//如果需要暴露连接,则返回连接,否则创建redis连接代理,默认为创建代理
        RedisConnection connToExpose = exposeConnection ? conn : createRedisConnectionProxy(conn);
	//调用redis回调接口的doInRedis方法
        Object result = action.doInRedis(connToExpose);
        if(pipeline && !pipelineStatus)
            conn.closePipeline();
	//处理redis回调接口的doInRedis方法返回结果
        obj = postProcessResult(result, conn, existingConnection);
	//释放连接与连接工厂的映射关系
        RedisConnectionUtils.releaseConnection(conn, factory);
        return obj;
        Exception exception;
        exception;
        RedisConnectionUtils.releaseConnection(conn, factory);
        throw exception;
    }


先来看这么一段
//从连接工厂获取连接
conn = RedisConnectionUtils.getConnection(factory);
//确定事务管理器中是否存在Redis连接工厂
existingConnection = TransactionSynchronizationManager.hasResource(factory);
//返回连接
preProcessConnection(conn, existingConnection);


//RedisConnectionUtils
public abstract class RedisConnectionUtils
{
    private static class RedisConnectionHolder
        implements ResourceHolder
    {

        public boolean isVoid()
        {
            return isVoid;
        }

        public RedisConnection getConnection()
        {
            return conn;
        }

        public void reset()
        {
        }

        public void unbound()
        {
            isVoid = true;
        }

        private boolean isVoid;
        private final RedisConnection conn;

        public RedisConnectionHolder(RedisConnection conn)
        {
            isVoid = false;
            this.conn = conn;
        }
    }
    //获取连接
    public static RedisConnection getConnection(RedisConnectionFactory factory)
    {
        return doGetConnection(factory, true, false);
    }
    public static RedisConnection doGetConnection(RedisConnectionFactory factory, boolean allowCreate, boolean bind)
    {
        Assert.notNull(factory, "No RedisConnectionFactory specified");
	//从事务管理器获取RedisConnectionHolder
        RedisConnectionHolder connHolder = (RedisConnectionHolder)TransactionSynchronizationManager.getResource(factory);
        if(connHolder != null)
            return connHolder.getConnection();
        if(!allowCreate)
            throw new IllegalArgumentException("No connection found and allowCreate = false");
        if(log.isDebugEnabled())
            log.debug("Opening RedisConnection");
	//从redis连接工厂获取连接
        RedisConnection conn = factory.getConnection();
        if(bind)
        {
	    //绑定redis连接工厂和连接句柄
            connHolder = new RedisConnectionHolder(conn);
            TransactionSynchronizationManager.bindResource(factory, connHolder);
            return connHolder.getConnection();
        } else
        {
            return conn;
        }
    }
}


//TransactionSynchronizationManager
public abstract class TransactionSynchronizationManager
{
    private static final ThreadLocal resources = new ThreadLocal();//连接工厂与连接的映射关系
    private static final ThreadLocal synchronizations = new ThreadLocal();
    private static final Comparator synchronizationComparator = new OrderComparator();
    private static final ThreadLocal currentTransactionName = new ThreadLocal();//事务名
    private static final ThreadLocal currentTransactionReadOnly = new ThreadLocal();//事务ReadOnly状态
    private static final ThreadLocal currentTransactionIsolationLevel = new ThreadLocal();//事务级别
    private static final ThreadLocal actualTransactionActive = new ThreadLocal();//实际事务状态
    //是否存在相关资源
     public static boolean hasResource(Object key)
    {
        Assert.notNull(key, "Key must not be null");
        Map map = (Map)resources.get();
        return map != null && map.containsKey(key);
    }
    //获取资源
 public static Object getResource(Object key)
    {
        Assert.notNull(key, "Key must not be null");
        Map map = (Map)resources.get();
        if(map == null)
            return null;
        Object value = map.get(key);
        return value;
    }
    //绑定资源
    public static void bindResource(Object key, Object value)
        throws IllegalStateException
    {
        Assert.notNull(key, "Key must not be null");
        Assert.notNull(value, "Value must not be null");
        Map map = (Map)resources.get();
        if(map == null)
        {
            map = new HashMap();
            resources.set(map);
        }
        if(map.containsKey(key))
            throw new IllegalStateException("Already value [" + map.get(key) + "] for key [" + key + "] bound to thread [" + Thread.currentThread().getName() + "]");
        map.put(key, value);
    }
}

从TransactionSynchronizationManager可以看出,ThreadLocal来管理连接工厂和连接的映射关系,事务级别和事务读写状态。

//返回连接
protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection)
{
    return connection;
}


再来看RedisTemplate的execute中的这么一段:
public Object execute(RedisCallback action, boolean exposeConnection, boolean pipeline)
{
	//如果需要暴露连接,则返回连接,否则创建redis连接代理,默认为创建代理
	RedisConnection connToExpose = exposeConnection ? conn : createRedisConnectionProxy(conn);
	//调用redis回调接口的doInRedis方法
	Object result = action.doInRedis(connToExpose);
	if(pipeline && !pipelineStatus)
	conn.closePipeline();
	//处理redis回调接口的doInRedis方法返回结果
	obj = postProcessResult(result, conn, existingConnection);
}


看一下关键代理的创建createRedisConnectionProxy(conn)

 protected RedisConnection createRedisConnectionProxy(RedisConnection pm)
    {
        Class ifcs[] = ClassUtils.getAllInterfacesForClass(pm.getClass(), getClass().getClassLoader());
	//创建redis连接动态代理
        return (RedisConnection)Proxy.newProxyInstance(pm.getClass().getClassLoader(), ifcs, new CloseSuppressingInvocationHandler(pm));
    }


//CloseSuppressingInvocationHandler
class CloseSuppressingInvocationHandler
    implements InvocationHandler
{
    private static final String CLOSE = "close";
    private static final String HASH_CODE = "hashCode";
    private static final String EQUALS = "equals";
    private final RedisConnection target;//动态代理,实际的目标类
    public CloseSuppressingInvocationHandler(RedisConnection target)
    {
        this.target = target;
    }

    public Object invoke(Object proxy, Method method, Object args[])
        throws Throwable
    {
        if(method.getName().equals("equals"))
            return Boolean.valueOf(proxy == args[0]);
        if(method.getName().equals("hashCode"))
            return Integer.valueOf(System.identityHashCode(proxy));
        if(method.getName().equals("close"))
            return null;
	//调用目标类的相应方法
        Object retVal = method.invoke(target, args);
        return retVal;
        InvocationTargetException ex;
        ex;
        throw ex.getTargetException();
    }
}


返回结果
protected Object postProcessResult(Object result, RedisConnection conn, boolean existingConnection)
{
     return result;
}

小节:
从StringRedisTemplate的构造中,主要初始化k-v,hash k-v的序列化工具,RedisTemplate
执行redis回调接口,首先获取redis连接工厂,再通过RedisConnectionUtils获取连接句柄,实际是委托给TransactionSynchronizationManager,如果redis事务管理器中没有与redis连接工厂关联的redis连接,则创建连接并与redis工厂绑定,然后如果需要暴露连接,则返回连接,
否则创建redis连接动态代理,默认为创建动态代理,最后调用redis回调接口的doInRedis方法,最后返回处理结果,释放连接与连接工厂的映射关系。redis事务管理器管理事务主要的思想使用
ThreadLocal来管理连接工厂和连接的映射关系,事务级别和事务读写状态。

总结:
JedisPoolConfig的功能主要是配置连接最大空闲
时间,存活数量,及等待时间;JedisPoolConfig的父类Config为GenericObjectPool的静态内部类,与连接池有关的属性在Config中,而属性的设置在JedisPoolConfig中;
JedisConnectionFactory在连接池配置和ip和port和密码等信息初始化后,
初始化Jedis连接池(初始化连接池及Jedis连接客户端工厂),JedisConnectionFactory获取连接的方式如果使用连接池,则直接从连接池JedisPool中获取,否则直接创建一个Jedis连接JedisConnection。从StringRedisTemplate的构造中,主要初始化k-v,hash k-v的序列化工具,RedisTemplate执行redis回调接口,首先获取redis连接工厂,再通过RedisConnectionUtils获取连接句柄,实际是委托给TransactionSynchronizationManager,如果redis事务管理器中没有与redis连接工厂关联的redis连接,则创建连接并与redis工厂绑定,然后如果需要暴露连接,则返回连接JedisConnection,否则创建redis连接动态代理,默认为创建动态代理,最后调用redis回调接口的doInRedis方法,最后返回处理结果,释放连接与连接工厂的映射关系。redis事务管理器管理事务主要的思想使用ThreadLocal来管理连接工厂和连接的映射关系,事务级别和事务读写状态。


//StringRedisSerializer
public class StringRedisSerializer
    implements RedisSerializer
{

    public StringRedisSerializer()
    {
        this(Charset.forName("UTF8"));
    }

    public StringRedisSerializer(Charset charset)
    {
        Assert.notNull(charset);
        this.charset = charset;
    }

    public String deserialize(byte bytes[])
    {
        return bytes != null ? new String(bytes, charset) : null;
    }

    public byte[] serialize(String string)
    {
        return string != null ? string.getBytes(charset) : null;
    }

    public volatile Object deserialize(byte x0[])
        throws SerializationException
    {
        return deserialize(x0);
    }

    public volatile byte[] serialize(Object x0)
        throws SerializationException
    {
        return serialize((String)x0);
    }
    private final Charset charset;
}
0
0
分享到:
评论

相关推荐

    Spring集成redis集群

    **Spring集成Redis集群详解** 在现代的Web应用程序开发中,数据缓存扮演着至关重要的角色,而Redis作为一款高性能的键值数据存储系统,被广泛应用于缓存、消息队列等多个场景。当业务规模扩大,单机Redis可能无法...

    spring redis集成

    **Spring Redis 集成详解** 在现代的Java开发中,Spring框架因其强大的功能和灵活性而备受青睐。随着数据存储技术的发展,Redis作为一款高性能的键值存储系统,被广泛应用于缓存、消息队列等多个场景。Spring为...

    Spring+redis5.05配置过程.docx

    Spring+Redis 5.05 配置过程详解 Spring 和 Redis 配置概述 在本文档中,我们将详细介绍如何配置 Spring 和 Redis 5.05,以实现高效的缓存和数据存储。Redis 作为一个高性能的 NoSQL 数据库,广泛应用于缓存、消息...

    Spring Data Redis中文参考文档

    1. **高级抽象层**:Spring Data Redis提供了一套高级抽象接口,使得开发人员能够更方便地与Redis进行交互,而无需深入理解底层协议细节。 2. **集成Spring生态**:该模块与Spring框架紧密结合,可以无缝集成到基于...

    spring集成redis

    **Spring 集成 Redis 知识点详解** 在现代Web开发中,Redis作为一个高性能的键值对数据存储系统,常被用作缓存、消息队列等多种场景。Spring框架提供了方便的集成方式,使得我们可以轻松地在Java应用中利用Redis的...

    Spring整合Redis

    **Spring 整合 Redis 知识点详解** 在现代Web应用开发中,缓存系统扮演着至关重要的角色,其中Redis作为一个高性能的键值对数据存储系统,被广泛应用于缓存、消息队列等多个场景。Spring作为Java领域的主流框架,与...

    Spring Boot Redis 集成配置详解

    Spring Boot Redis 集成配置详解 Spring Boot 是一个基于Java的开源框架,旨在简化基于Spring的应用程序的搭建过程。Redis 是一个开源的、基于内存的数据结构存储系统,可以用作数据库、消息队列、 Cache 等。集成 ...

    spring集成redis cluster详解

    主要介绍了spring集成redis cluster详解,分享了maven依赖,Spring配置,增加connect-redis.properties 配置文件等相关内容,具有一定参考价值,需要的朋友可以了解下。

    Spring-data-redis使用指南

    **Spring Data Redis** 是 **Spring Data** 家族中的一个模块,它为 **Redis** 提供了一套方便的操作接口,使得开发人员可以更加高效地利用 **Redis** 进行数据存储与检索。本章节将对 Spring Data Redis 的主要功能...

    spring-redis jar

    《Spring与Redis的集成应用详解》 在现代的Web开发中,数据缓存技术起着至关重要的作用,它能够显著提升应用的性能和响应速度。Spring框架作为Java领域中的主流开发框架,提供了丰富的扩展性,使得与其他技术的集成...

    spring-redis.txt

    ### Spring 整合 Redis 配置详解 在现代软件开发中,Redis 作为一种高性能的键值存储数据库,常被用于缓存、会话管理、消息队列等多种应用场景。Spring 框架则提供了丰富的功能来简化 Java 应用程序的开发。本文将...

    详解SSH框架和Redis的整合

    1. **相关Jar文件**:为了实现SSH与Redis的整合,需要引入Redis客户端Jedis的jar包(如jedis-2.3.1.jar)以及Spring对Redis支持的相关jar包(如spring-data-redis-1.3.4.RELEASE.jar)。此外,还需要连接池管理的库...

    spring-data-redis实例

    Spring Data Redis是Spring项目下的一个模块,它提供了一套完整的Redis操作API,简化了与Redis数据库的交互。通过Spring Data Redis,开发者可以方便地进行键值对操作、哈希存储、列表、集合和有序集合的操作,以及...

    Spring Redis缓存实例

    **Spring Redis 缓存实例详解** 在现代的Web应用程序开发中,缓存是提高系统性能的关键技术之一。Spring框架提供了一种优雅的方式来整合缓存管理,其中包括对Redis的支持。Redis是一个开源的、高性能的键值数据库,...

    Spring Boot整合redis

    Thymeleaf是一个强大的服务器端模板引擎,可以与Spring Boot无缝集成。在`pom.xml`或`build.gradle`中添加Thymeleaf依赖,然后在`src/main/resources/templates`目录下创建HTML模板文件。在Controller中返回...

    spring boot - redis-1

    **Spring Boot 集成 Redis 知识点详解** ...在"spring boot - redis-1"的示例代码中,开发者可能已经演示了这些基本操作,进一步了解和学习这个示例将有助于加深对Spring Boot与Redis集成的理解。

    springmvc集成redis的Demo基于maven(内有redis)

    **Spring MVC 集成 Redis 知识点详解** 在当今的互联网开发中,缓存技术扮演着至关重要的角色,而 Redis 作为一款高效的内存数据结构存储系统,被广泛应用于缓存、消息队列等场景。Spring MVC 是一个成熟的、广泛...

    spring-boot2集成redis

    **Spring Boot 2 集成 Redis 知识点详解** Spring Boot 2 提供了对 Redis 的便捷集成,使得开发者能够快速地在 Spring 应用中利用 Redis 的高性能存储特性。以下将详细介绍如何在 Spring Boot 2 项目中集成 Redis,...

    Spring Boot Redis 实现分布式锁的方法详解.docx

    Spring Boot 提供了与 Redis 集成的便捷方式,使得开发者能够快速实现分布式锁功能。本篇文章将详细讲解如何利用 Spring Boot 结合 Redis 实现分布式锁。 首先,理解分布式锁的基本概念。分布式锁是在分布式系统中...

Global site tag (gtag.js) - Google Analytics