博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring整合redis之hello
阅读量:7226 次
发布时间:2019-06-29

本文共 2644 字,大约阅读时间需要 8 分钟。

1.pom.xml文件

org.springframework
spring-core
4.1.7.RELEASE
org.springframework.data
spring-data-redis
1.4.1.RELEASE
org.springframework
spring-test
3.1.2.RELEASE
test
redis.clients
jedis
2.6.2
junit
junit
4.8.2
test
org.codehaus.mojo
tomcat-maven-plugin
1.1
9996
org.apache.maven.plugins
maven-compiler-plugin
2.3.2
1.7
1.7

  2.、applicationContext.xml

applicationContext-cache.xml

  测试类

package com.baidu.redistest;import java.util.concurrent.TimeUnit;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = "classpath:applicationContext.xml")public class Demo {	@Autowired	private RedisTemplate
redisTemplate; @Test public void testRedis() { // 保存key value // 设置30秒失效 redisTemplate.opsForValue().set("c", "北京", 300, TimeUnit.SECONDS); System.out.println(redisTemplate.opsForValue().get("c")); }}

  

测试成功

 

转载于:https://www.cnblogs.com/fjkgrbk/p/spring_redis.html

你可能感兴趣的文章
.net面试题系列文章七(附答案)
查看>>
FastSocket
查看>>
ionic $ionicSlideBoxDelegate 滑动框事件
查看>>
点击文字,把input type="radio"也选中
查看>>
第一章 Java多线程技能
查看>>
Java 集合系列-第八篇-Map架构
查看>>
springmvc 3.2 @MatrixVariable bug 2
查看>>
React-Native PanResponder手势识别器
查看>>
IOS11 光标错位问题
查看>>
如何设计用户登录
查看>>
linux安装mysql5.7.19
查看>>
Zookeeper+ActiveMQ 集群实现
查看>>
加权有向图问题2----多源最短路径问题(Floyd算法)和关键路径算法
查看>>
logback logback.xml常用配置详解(三) <filter>
查看>>
KgMall B2B/B2B2c/C2C版店铺商号初始化
查看>>
Linux内核的ioctl函数学习
查看>>
Liunx Shell入门
查看>>
Thread的中断
查看>>
linux --- 内存管理
查看>>
PostgreSQL
查看>>