stringRedisTemplate.opsForList()
时间: 2024-05-06 13:19:50 浏览: 39
The method `opsForList()` is used to retrieve a Redis list-specific operations object that can be used to perform various list operations on Redis.
Example usage:
```
ListOperations<String, String> listOps = stringRedisTemplate.opsForList();
listOps.leftPush("mylist", "value1");
listOps.rightPush("mylist", "value2");
List<String> values = listOps.range("mylist", 0, -1);
```
In the above example, we first retrieve the `ListOperations` object using `opsForList()`, and then use it to perform operations such as `leftPush()`, `rightPush()`, and `range()` on a Redis list named "mylist". The `leftPush()` and `rightPush()` methods push values to the left and right ends of the list respectively, and the `range()` method retrieves all values in the list.
Note that the `ListOperations` object returned by `opsForList()` is parameterized with the key and value types of the Redis list. In the example above, we use `String` as both the key and value types.
阅读全文