SpringBoot -- 集成Redis/CacheManager
来源:互联网 发布:知乎 好听的民谣下载 编辑:程序博客网 时间:2024/06/05 16:22
前置工作
- 了解Redis、Cache
- spring-data-redis
Demo
引入 spring-data-Redis
build.gradle
- 1
- 2
- 1
- 2
创建 RedisConfig,与Spring Cache进行集成;
- 与Spring Cache进行集成时需要key、value的 序列化,不然会出现 \xAC\xED\x00\x05t\x00\x06之类的
- 与Spring Cache集成后redis key会存入 cachekey+~keys中 xxx~keys
RedisConfig.Java
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
配置 redis连接信息,redis启用了密钥
application.yml
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
创建 Cache 操作类
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
创建 Controller 类此处用 集成Mybatis时的controller
- 加入缓存key private final static String TEST_REDIS = “test_redis”
- 设置key-value :
Cache cache = cacheManager.getCache(TEST_REDIS);
putCache(cache,”test_aa”,”111111”);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
测试
访问 http://localhost:10002/dbserver/accountInfo?name=cwenao
Key 存储在 test_redis~keys中
- test_redis~keys中 test_redis为 Cache的key
value存储在 test_redis~keys中相对应的key
- test_aa 为我们设置的redis key
代码
代码请移步 Github参考地址
如有疑问请加公众号(K171),如果觉得对您有帮助请 github start
0 0
- SpringBoot -- 集成Redis/CacheManager
- SpringBoot -- 集成Redis/CacheManager
- Springboot集成ehcache时获取CacheManager自定义添加其他缓存
- springboot集成redis
- springboot集成Redis
- springboot 集成redis 哨兵
- springboot集成Redis
- SpringBoot集成Redis
- springboot集成redis详解
- 关于SpringBoot 集成 Redis
- SpringBoot集成Redis
- springboot集成redis
- SpringBoot集成Redis
- SpringBoot集成Redis
- 在SpringBoot中集成Redis
- SpringBoot 入门教程:集成mybatis,redis
- SpringBoot 入门教程:集成mybatis,redis
- SpringBoot 入门教程:集成mybatis,redis
- python str byte hex
- iOS-对象为空的判断(nil、null)
- talib 翻转校正图片等
- day82_babasport第八天
- qmake一些话题
- SpringBoot -- 集成Redis/CacheManager
- FastRCNN 训练自己数据集(一)——编译配置
- 近几年目标跟踪算法发展综述(上)
- Docker网络详解-一
- Spring 3之MVC & Security简单整合开发(二)
- 获取系统内安装程序列表
- Java容器-List和Set
- 测试libcurl库是否正确安装
- 连接 虚拟机 linux 网卡配置