• 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常用集合使用说明-opsForList(三)

    列表类型的内部编码有两种。

      • ziplist(压缩列表):当列表的元素个数小于list-max-ziplist-entries配置 (默认512个),同时列表中每个元素的值都小于list-max-ziplist-value配置时 (默认64字节),Redis会选用ziplist来作为列表的内部实现来减少内存的使 用。
      • linkedlist(链表):当列表类型无法满足ziplist的条件时,Redis会使用 linkedlist作为列表的内部实现。
  • 相关阅读:
    axios——post请求时把对象obj数据转为formdata格式
    【工作问题记录】
    如何在Vue项目中使用Element组件
    Manjaro 安装教程
    真 ● 禁秘技 ● 奥义 ● 终端美化
    Docker下MySQL的安装
    Linux Nvidia显卡驱动安装
    Linux下Matlab的安装
    解决SQLPLUS无法使用上下箭头
    @Transactional+@Autowired出现的lateinit property xx has not been initialized错误
  • 原文地址:https://www.cnblogs.com/meijsuger/p/12040376.html
Copyright © 2020-2023  润新知