package cn.reghao.tnb.content.app.util.redis.ds;

import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author reghao
 * @date 2021-03-07 17:44:23
 */
@Component
public class RedisList {
    private final ListOperations<String, Object> listOps;

    public RedisList(RedisTemplate<String, Object> redisTemplate) {
        this.listOps = redisTemplate.opsForList();
    }

    public Object blpop(String key) {
        return listOps.leftPop(key);
    }

    public void add(String key, Object value) {
        listOps.leftPush(key, value);
    }

    public void addAll(String key, List<Object> values) {
        listOps.leftPushAll(key, values);
    }

    public List<Object> getAll(String key) {
        return listOps.range(key, 0, -1);
    }
}
