• 【原】Spring整合Redis(第一篇)—SDR简述


    1、SDR说明
    Spring Data Redis(SDR),是SpringFramework提供的一套简化访问Redis的API,是对Jedis的又一层封装。
    SDR集成了Jedis,JRedis,SRP,Lettuce这四种开源的Redis Connector,这些Connector都是针对于Redis的开源Java库。其中,JRedis和SRP从spring-data-redis1.7开始,就不支持了。

    2、RedisTemplate说明
    RedisTemplate是SDR的一个核心Helper类,该类是一个高级的抽象(对Jedis的又一层封装),它封装了对Redis中的数据的CRUD操作,包含“高级封装”。
    (1)高级封装(推荐使用)
    高级封装的操作包含:OpsForValue(),OpsForList(),OpsForSet(),OpsForZset(),OpsForHash()等等。
    SDR官方文档中对Redistemplate的介绍:the template is in fact the central class of the Redis module due to its rich feature set. The template offers a high-level abstraction for Redis interactions.
      通过Redistemplate可以调用ValueOperations和ListOperations等等方法,分别是对Redis命令的高级封装。
      但是ValueOperations等等这些命令最终是要转化成为RedisCallback来执行的。也就是说通过使用RedisCallback可以实现更强的功能,SDR文档对RedisCallback的介绍:RedisTemplate and StringRedisTemplate allow the developer to talk directly to Redis through the RedisCallback interface. This gives complete control to the developer as it talks directly to the RedisConnection。

    (2)从高级封装获得低级封装的过渡:
    RedisOperations<String, Object> operations = opsForValue.getOperations();

    3、RedisConnection提供了“低级封装”。
    (1)低级封装
    低级封装的操作是通过连接到Redis的Connection对象,直接对Redis数据进行操作。
    低级封装的核心是:redisTemplate.execute(new RedisCallback(){})

    【参考资料】
    01.《Spring Data Redis官方文档》:
    http://docs.spring.io/spring-data/redis/docs/1.7.2.RELEASE/reference/html/

  • 相关阅读:
    Pytorch学习(一)基础语法篇
    CSAPP深入理解计算机系统(第二版)第三章家庭作业答案
    理解DP(持续更新)
    LeetCode题解 | 215. 数组中的第K个最大元素
    快速排序
    浅谈设计模式(java)——从lol来看观察者模式
    <小虾米的android学习之旅1>Android框架
    程序员如何用技术变现?
    为了反击爬虫,前端工程师的脑洞可以有多大?
    如何成为一名爬虫工程师?(顺带提供工作机会)
  • 原文地址:https://www.cnblogs.com/zjrodger/p/5800593.html
Copyright © 2020-2023  润新知