zoukankan      html  css  js  c++  java
  • 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作为列表的内部实现。
  • 相关阅读:
    【转】 grep 文件报错 “Binary file ... matches”
    JS 将值插入数组中
    Vue 刷新当前页面,并重新加载页面数据
    Vue 获得所选中目标的状态(checked)以及对应目标的数据,并进行相应的操作
    JS --- 如何获取一个对象的类型
    vue-cli项目开发/生产环境代理实现跨域请求+webpack配置开发/生产环境的接口地址
    VUE 处理文本框获焦点高亮
    VUE项目问题之:去掉url中的#/
    关于移动端终极适配解决方案
    VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法
  • 原文地址:https://www.cnblogs.com/meijsuger/p/12040376.html
Copyright © 2011-2022 走看看