Skip to content

Commit d0de234

Browse files
committed
add StringRedisTemplate
1 parent fd5dbd8 commit d0de234

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

SpringBootRedis/src/test/java/com/tistory/heowc/SimpleRedisTemplateTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.junit.runners.MethodSorters;
77
import org.springframework.beans.factory.annotation.Autowired;
88
import org.springframework.boot.test.context.SpringBootTest;
9+
import org.springframework.data.redis.core.ListOperations;
910
import org.springframework.data.redis.core.RedisTemplate;
1011
import org.springframework.data.redis.core.ValueOperations;
1112
import org.springframework.test.context.junit4.SpringRunner;
@@ -21,17 +22,18 @@ public class SimpleRedisTemplateTest {
2122

2223
@Autowired
2324
private RedisTemplate<String, String> redisTemplate;
25+
2426
@Resource(name = "redisTemplate")
25-
private ValueOperations<String, String> listOps;
27+
private ValueOperations<String, String> valueOps;
2628

2729
@Test
28-
public void test1_push() throws Exception {
29-
listOps.set(KEY, "wonchul");
30+
public void test1_set() throws Exception {
31+
valueOps.set(KEY, "wonchul");
3032
}
3133

3234
@Test
33-
public void test2_pop() throws Exception {
34-
System.out.println(String.format("pop [ %s ]", listOps.get(KEY)));
35+
public void test2_get() throws Exception {
36+
System.out.println(String.format("pop [ %s ]", valueOps.get(KEY)));
37+
redisTemplate.delete(KEY);
3538
}
36-
37-
}
39+
}

SpringBootRedis/src/test/java/com/tistory/heowc/StringRedisTemplateTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
1515
public class StringRedisTemplateTest {
1616

17-
private static final String KEY = "test_string";
17+
private static final String KEY_1 = "set_get";
1818

1919
@Autowired StringRedisTemplate stringRedisTemplate;
2020

2121
@Test
22-
public void test1_push() throws Exception {
23-
stringRedisTemplate.opsForValue().set(KEY, "wonchul");
22+
public void test1_set() throws Exception {
23+
stringRedisTemplate.opsForValue().set(KEY_1, "wonchul");
2424
}
2525

2626
@Test
27-
public void test2_pop() throws Exception {
28-
System.out.println(String.format("pop [ %s ]", stringRedisTemplate.opsForValue().get(KEY)));
27+
public void test2_get() throws Exception {
28+
System.out.println(String.format("pop [ %s ]", stringRedisTemplate.opsForValue().get(KEY_1)));
29+
stringRedisTemplate.delete(KEY_1);
2930
}
30-
31-
}
31+
}

0 commit comments

Comments
 (0)