电光石火-穿越时空电光石火-穿越时空


RedisTemplate操作list

redis中的列表:

  • 一个列表最多可以存储2^32 -1个元素
  • 可以对列表两端插入(push)和弹出(pop)
  • 元素有序且可重复
命令操作返回值
range(K key, long start, long end)获取元素【lrange】List<V>
trim(K key, long start, long end)截取列表的内容,从start到end中间的留下,两端的删除【ltrim】void
size(K key)获取列表长度【llen】Long
leftPush(K key, V value)从列表左侧插入元素【lpush】Long
leftPushAll(K key, V... values)~Long
leftPushAll(K key, Collection<V> values)~Long
leftPushIfPresent(K key, V value)左侧添加元素(如果存在的话)【lpush】Long
leftPush(K key, V pivot, V value)在pivot(匹配到的第一个)之前(左侧)添加value【linsert】Long
rightPush(K key, V value)从列表右侧插入元素【rpush】Long
rightPushAll(K key, V... values)【rpush】Long
rightPushAll(K key, Collection<V> values)【rpush】Long
rightPushIfPresent(K key, V value)右侧添加元素(如果存在的话)【rpush】Long
rightPush(K key, V pivot, V value)在pivot(匹配到的第一个)之后(右侧)添加value【linsert】Long
set(K key, long index, V value)设置值,有则覆盖,没有则新增【lset】void
remove(K key, long count, Object value)删除元素,见下方说明【lrem】Long
index(K key, long index)查找元素【lindex】V
leftPop(K key)从列表左侧弹出元素【lpop】V
leftPop(K key, long timeout, TimeUnit unit)弹出列表左侧元素,timeout为超时时间,TimeUnit时间单位【blpop】V
rightPop(K key)从列表右侧弹出元素【rpop】V
rightPop(K key, long timeout, TimeUnit unit)弹出列表右侧元素,timeout为超时时间,TimeUnit时间单位【brpop】V
rightPopAndLeftPush(K sourceKey, K destinationKey)弹出右侧元素并向左侧插入元素V
rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit)弹出右侧元素并向左侧插入元素。timeout 超时时间V
getOperations() RedisOperations<K, V>
  • remove(K key, long count, Object value) :

conut = 0,删除所有匹配的元素
count > 0 删除匹配元素开始,从左到右最多count个元素
count < 0 删除匹配元素开始,从右到左最多count个元素

本博客所有文章如无特别注明均为原创。作者:似水的流年
版权所有:《电光石火-穿越时空》 => RedisTemplate操作list
本文地址:http://www.ilkhome.cn/index.php/archives/688/
欢迎转载!复制或转载请以超链接形式注明,文章为 似水的流年 原创,并注明原文地址 RedisTemplate操作list,谢谢。

评论