服务发布(无redis版)
This commit is contained in:
@ -0,0 +1,53 @@
|
||||
package com.bipt.intelligentapplicationorchestrationservice;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.core.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@SpringBootTest
|
||||
public class RedisTest {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@Test
|
||||
public void testRedisTemplate(){
|
||||
System.out.println(redisTemplate);
|
||||
ValueOperations valueOperations = redisTemplate.opsForValue();
|
||||
HashOperations hashOperations = redisTemplate.opsForHash();
|
||||
ListOperations listOperations = redisTemplate.opsForList();
|
||||
SetOperations setOperations = redisTemplate.opsForSet();
|
||||
ZSetOperations zSetOperations = redisTemplate.opsForZSet();
|
||||
}
|
||||
@Test
|
||||
public void testString(){
|
||||
//set get setex setnx
|
||||
redisTemplate.opsForValue().set("name","小明");
|
||||
String city =(String) redisTemplate.opsForValue().get("name");
|
||||
System.out.println(city);
|
||||
redisTemplate.opsForValue().set("code","1234",3, TimeUnit.MINUTES);
|
||||
redisTemplate.opsForValue().setIfAbsent("lock","1");
|
||||
redisTemplate.opsForValue().setIfAbsent("lock","2");
|
||||
}
|
||||
@Test
|
||||
public void testHash(){
|
||||
// hset hget hdel hkeys hvals
|
||||
HashOperations hashOperations = redisTemplate.opsForHash();
|
||||
hashOperations.put("100","name","tom");
|
||||
hashOperations.put("100","age","20");
|
||||
|
||||
String name = (String) hashOperations.get("100", "name");
|
||||
System.out.println(name);
|
||||
|
||||
Set keys = hashOperations.keys("100");
|
||||
System.out.println(keys);
|
||||
List values = hashOperations.values("100");
|
||||
System.out.println(values);
|
||||
hashOperations.delete("100","age");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user