SpringRedisTemplate操作Redis「适合有一定经验才能掌握」


脑图

PS:今天分享的主体是SpringRedisTemplate操作Redis。后面会和大家一起一起探讨一下关于Redis的集群搭建以及数据同步问题。如果对于Redis有疑问,请私聊小编,小编统一发放资料。今天先简单的介绍一下如下内容:

  • 如何在项目中集成Redis

  • Redis的常见API分享

1、Redis官网: https://projects.spring.io/spring-data-redis/

2、集成Redis:

  • 2-1:导包:

导包

  • 2-2:配置RedisTemplate

配置RedisTemplate

PS:注意:序列化数据,否则存入到redis都是二进制数据

  • 2-3:编写一个测试类Application

测试类Application

3、Spring操作Redis的API

  • 3-1:可以参考官网 https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#redis:template

  • 3-2:Spring-data-redis中针对jedis客户端中大量api进行了归类封装,将同一类型操作封装为operation接口

  • 3-3:提供了对key的“bound”(绑定)便捷化操作API,可以通过bound封装指定的key,然后进行一系列的操作而无须“显式”的再次指定Key,即BoundKeyOperations:

BoundValueOperations:字符串类型操作

BoundListOperations:列表类型操作

BoundSetOperations:集合类型操作

BoundZSetOperations:有序集合类型操作

  • 3-3-1:BoundListOperations

BoundListOperations

ps:注意TimeUnit(本身是枚举):TimeUnit 表示给定单元粒度的时间段,它提供在这些单元中进行跨单元转换和执行计时及延迟操作的实用工具方法。TimeUnit 不维护时间信息,但是有助于组织和使用可能跨各种上下文单独维护的时间表示形式。 TimeUnit 主要用于通知基于时间的方法如何解释给定的计时参数。

3-3-2:BoundValueOperations

BoundValueOperations

3-3-3:BoundSetOperations

3-3-4:Bound ZsetOperations

Bound ZsetOperations

3-3-5:BoundHashOperations

BoundHashOperations

PS:大家有什么想要分享的内容!可以在评论下方留言!!!

❤如果需要小编每天的发文资料,请私信小编即可!

❤图文均为头条号IT蛇精病原创,旨在分享。

❤提问/互动请留言,可直接在最底右下方"写留言即可"

❤如果觉得写得不错请点击“订阅”,每天更新原创内容!

举报
评论 0