(1)、引入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
<dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.48.Final</version> </dependency>
第二个依赖缺少可能提示:
ClassNotFoundException: io.netty.util.internal.logging.InternalLoggerFactory
(2)、配置redis信息
application.properties中加载redis配置文件
# redis config spring.profiles.include=redis
创建redis配置文件application-redis.properties
### redis config spring.redis.host=192.168.0.35 spring.redis.port=6379 spring.redis.password=123456
(3)、注入redis
@Autowired private StringRedisTemplate redisTemplate;
(4)、操作redis
// 获取authorization String authorization = x2Service.getAuthorization(); // 保存authorization到redis redisTemplate.opsForValue().set(tokenRedisKey, authorization);
// 获取authorization String authorization = (String) redisTemplate.opsForValue().get(tokenRedisKey);
百度教程虽然多,但是2.X都有问题,缺少依赖会报错ClassNotFoundException: io.netty.util.internal.logging.InternalLoggerFactory,折腾一个上午。
public class test { public static void main(String[] args) { &...
java限制1个方法同一时间只能被一个线程访问public synchronized void setOrderPay(){ }加上synchronized 修饰符即可...
在java中字符串属于对象,刚开始我就疑惑为什么int char等类型都是小写,结果String是大写,java太反人类,后来才知道String是对象。(1).java创建字符串String text = "net"; String tex...
(1).java睡眠函数Thread.sleep(时间); //单位为毫秒(2).java睡眠函数例子Date dNow = new Date(); SimpleDateFormat ft = new&nbs...
pattern表示正则表达式,接收正则表达式作为参数例子:String content = "my name is gaojiufeng"; String pattern = "....
java正则表达式的捕获组捕获组可以将匹配到的结果根据正则中的括号进行分组,这里变量我加了$符,php转java的坏习惯,懒得改了,能跑就行// 匹配字符串 String $line = "gaojiufeng 1994! ok?...