zoukankan      html  css  js  c++  java
  • 【原】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/

  • 相关阅读:
    最短路+线段交 POJ 1556 好题
    判断线段和直线相交 POJ 3304
    nginx配置pathinfo模式,解决访问404
    使用ORM关联关系,如何自己关联自己
    PHPCMS
    linux安装redis服务,配置PHP扩展
    后台银行卡算法
    静态类和非静态类
    PHP的闭包和匿名函数
    php获取前一天时间段,每个月的第一天到最后一天
  • 原文地址:https://www.cnblogs.com/zjrodger/p/5800593.html
Copyright © 2011-2022 走看看