前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >RedisTemplate操作list

RedisTemplate操作list

作者头像
似水的流年
发布2020-08-25 09:54:25
2.3K0
发布2020-08-25 09:54:25
举报
文章被收录于专栏:电光石火电光石火

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个元素

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-08-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档