2019-05-16 19:24:32 +08:00
|
|
|
package db;
|
|
|
|
|
|
2019-05-18 13:07:25 +08:00
|
|
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2019-05-16 19:24:32 +08:00
|
|
|
public class RedisTest {
|
2019-05-18 13:07:25 +08:00
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
StringRedisTemplate redisTemplate = getRedisTemplate();
|
2021-11-03 17:35:01 +08:00
|
|
|
redisTemplate.opsForZSet().add("test","1000",78);
|
|
|
|
|
redisTemplate.opsForZSet().add("test","1000",2);
|
|
|
|
|
System.out.println("ok");
|
2019-05-18 13:07:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static StringRedisTemplate getRedisTemplate(){
|
|
|
|
|
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
|
|
|
|
|
//设置host
|
2021-11-03 17:35:01 +08:00
|
|
|
connectionFactory.setHostName("60.1.1.21");
|
2019-05-18 13:07:25 +08:00
|
|
|
//设置端口
|
|
|
|
|
connectionFactory.setPort(6379);
|
|
|
|
|
//初始化connectionFactory
|
|
|
|
|
connectionFactory.afterPropertiesSet();
|
2021-11-03 17:35:01 +08:00
|
|
|
// 设置数据库
|
|
|
|
|
connectionFactory.setDatabase(2);
|
2019-05-18 13:07:25 +08:00
|
|
|
//实例化
|
|
|
|
|
return new StringRedisTemplate(connectionFactory);
|
|
|
|
|
}
|
2019-05-16 19:24:32 +08:00
|
|
|
}
|