1、依赖包
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><version>2.3.8.RELEASE</version>
</dependency>
2、注入
@Autowired
private StringRedisTemplate redisTemplate;
3、Pop 批量数据
public List<String> leftPops(final String key, final int count) {final List<Object> txResults = this.redisTemplate.execute(new SessionCallback<List<Object>>() {@Overridepublic List<Object> execute(final RedisOperations operations) throws DataAccessException {operations.multi();operations.opsForList().range(key, 0, count - 1);operations.opsForList().trim(key, count, -1);return operations.exec();}});if (CollectionUtils.isEmpty(txResults)) {return Collections.emptyList();}final Object object = txResults.get(0);if (object instanceof ArrayList) {//返回最终结果return (List<String>) object;}return Collections.emptyList();
}