1. If start—end maintains the overall order, there will be no problem
2. Follow the order, even if start N-1 can also query data
3. Special usage: Through stringRedisTemplate.opsForList().range(key, 0, -1), you can query the first index to the last index ( That is, all data)
@Resource private StringRedisTemplate stringRedisTemplate; @Test void testRedis() { String key = "testList"; String[] data = new String[]{"1_1", "1-2", "2_1", "2_2"}; Boolean flag = stringRedisTemplate.hasKey(key); if (!flag) { stringRedisTemplate.opsForList().leftPushAll(key, data); } List<String> range = stringRedisTemplate.opsForList().range(key, -100, -1); System.out.println("range = " + range); }
From the results: the 4th from the last index - the 1st from the last index
From the results: the third from the last index - the first from the last index
From the results: the third from the last index - the second from the last index
From the results: the second from the last index - the third from the last index will not work, from The third from the bottom of the index - the second from the bottom of the index is fine.
Conclusion: Starting from the Nth index, it must be in order (i.e. -N, -(N-1), -(N-2),..., -1). Reverse order is not possible. ’
From the results: From the first index - the fourth index
##5.2, stringRedisTemplate.opsForList().range(key, 1,2) From the results: From the second index - the third index##5.3, stringRedisTemplate.opsForList().range(key, 2,1)
Conclusion : Starting from index 0, it must be in order (i.e. 0, 1, 2,..., N-1), reverse order is not possible
6. Test index Countdown——Positive index (positive index, subscript 0 is the first one)
6.2. stringRedisTemplate.opsForList().range(key, -4, 3)
6.3, stringRedisTemplate.opsForList().range(key, -4, 5)
Conclusion: It is no problem to exceed in order
The above is the detailed content of How to use opsForList().range() in redis. For more information, please follow other related articles on the PHP Chinese website!