|
@@ -0,0 +1,55 @@
|
|
|
+package com.sf;
|
|
|
+
|
|
|
+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.ListOperations;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+
|
|
|
+@SpringBootTest
|
|
|
+public class RedisTests {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate redisTemplate;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testString() {
|
|
|
+
|
|
|
+// // 来自于 spring-redis-data.jar
|
|
|
+// redisTemplate.opsForValue().set("key12", abc);
|
|
|
+// System.out.println(redisTemplate.opsForValue().get("key12"));
|
|
|
+
|
|
|
+ redisTemplate.opsForValue().set("key11", 10L);
|
|
|
+ redisTemplate.opsForValue().increment("key11");
|
|
|
+ System.out.println(redisTemplate.opsForValue().get("key11"));
|
|
|
+
|
|
|
+ redisTemplate.opsForValue().append("key14", "10");
|
|
|
+ redisTemplate.opsForValue().append("key14", "20");
|
|
|
+ System.out.println(redisTemplate.opsForValue().get("key14"));
|
|
|
+
|
|
|
+// mylist 1 2 3 4 5 rpush
|
|
|
+// mylist 10 20 30 40 50 1 2 3 4 5 lpush
|
|
|
+// mylist 长度 llen
|
|
|
+// mylist 弹出最后一个 rpop 10 20 30 40 50 1 2 3 4
|
|
|
+// mylist 只取出前五个 ltrim 10 20 30 40 50
|
|
|
+// redisTemplate.opsForList().
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testList() {
|
|
|
+ ListOperations forList = redisTemplate.opsForList();
|
|
|
+ String key = "mylist11";
|
|
|
+ forList.rightPushAll(key, "1", "2", "3", "4", "5"); //rightPush
|
|
|
+// forList.leftPushAll(key, "10", "20", "30", "40", "50");
|
|
|
+ // 50 40 30 20 10 1 2 3 4 5
|
|
|
+ forList.leftPushAll(key, "50", "40", "30", "20", "10");
|
|
|
+ // llen
|
|
|
+ System.out.println(forList.size(key));
|
|
|
+ // lrange
|
|
|
+ System.out.println(forList.range(key, 0, -1));
|
|
|
+
|
|
|
+ forList.rightPop(key);
|
|
|
+ forList.trim(key, 0, 4);
|
|
|
+ System.out.println(forList.range(key, 0, -1));
|
|
|
+ }
|
|
|
+}
|