Redis实战应用举例

时间:2022-01-31 20:30:57
1.Maven导包
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
2.Spring配置文件加入节点IP
redis:
nodes:
- 192.168.2.210:7000
- 192.168.2.210:7001
- 192.168.2.210:7002
- 192.168.2.210:7003
- 192.168.2.210:7004
- 192.168.2.210:7005
3.注入依赖
@Autowiredprivate JedisCluster redis;
4.常用方法举例
添加键值对
set(final String key, final String value)
设置失效时间
expire(final String key, final int seconds)

获取键值对
get(final String key)