1.将值追加到列表

RPUSH key value [value ...]
summary: Append one or multiple values to a list
since: 1.0.0

127.0.0.1:6379> RPUSH mylist value1 value2 value3
(integer) 3

2.获取列表的长度

LLEN key
summary: Get the length of a list
since: 1.0.0

127.0.0.1:6379> llen mylist
(integer) 3

3.获取并移除列表中第一个元素

BLPOP key [key ...] timeout
summary: Remove and get the first element in a list, or block until one is available
since: 2.0.0

127.0.0.1:6379> blpop mylist 3
1) "mylist" ##列表key
2) "value1" #列表当前第一个值
127.0.0.1:6379> blpop mylist 3
1) "mylist"
2) "value2"
127.0.0.1:6379> blpop mylist 3
1) "mylist"
2) "value3"
127.0.0.1:6379> blpop mylist 3 列表已经不存在value

(nil)
(3.78s)

4.获取并移除列表中的最后一个元素

BRPOP key [key ...] timeout
summary: Remove and get the last element in a list, or block until one is available
since: 2.0.0

127.0.0.1:6379> brpop list1 3
1) "list1" #列表键名
2) "value3" #列表最后一个值

5.出栈list中的一个value,并放入另一个list中,并返回该值

BRPOPLPUSH source destination timeout
summary: Pop a value from a list, push it to another list and return it; or block until one is available
since: 2.2.0

127.0.0.1:6379> BRPOPLPUSH list1 list2 3
"value2"

6.获取指定位置的value值,返回的是该位置的值,无值或超出边界返回nil

LINDEX key index
summary: Get an element from a list by its index
since: 1.0.0

7.在列表一个元素的之前或之后插入一个元素,返回当前列表的长度

LINSERT key BEFORE|AFTER pivot value
summary: Insert an element before or after another element in a list
since: 2.2.0

127.0.0.1:6379> linsert ml before v2 value2
(integer) 5  在v2之前插入值value2

8.栈顶元素出栈

LPOP key
summary: Remove and get the first element in a list
since: 1.0.0

127.0.0.1:6379> lpop ml
"v1"

9.向list中添加一个或多个value,后加入的值,index在前(将元素压入栈顶)

LPUSH key value [value ...]
summary: Prepend one or multiple values to a list
since: 1.0.0

127.0.0.1:6379> lpush list2 val1 val2 val3 val4 val5
(integer) 6
127.0.0.1:6379> lindex list2 0
"val5"

10.只有当列表存在时,才从栈顶压入元素

LPUSHX key value
summary: Prepend a value to a list, only if the list exists
since: 2.2.0

11.获取指定范围的list的value值

LRANGE key start stop
summary: Get a range of elements from a list
since: 1.0.0

12.从列表中移除元素(当list中存在多个重复的值时,count确定要移除几个value)

LREM key count value
summary: Remove elements from a list
since: 1.0.0

13.通过元素的索引index设置value

LSET key index value
summary: Set the value of an element in a list by its index
since: 1.0.0

127.0.0.1:6379> lset list2 3 namew #修改第三个位置的值
OK
  1. 将列表修剪到指定的范围

LTRIM key start stop
summary: Trim a list to the specified range
since: 1.0.0

15.移除并获取列表中的最后一个元素

RPOP key
summary: Remove and get the last element in a list
since: 1.0.0

16.移除列表中的最后一个元素,追加到另一个列表中,并返回该值

RPOPLPUSH source destination
summary: Remove the last element in a list, append it to another list and return it
since: 1.2.0

17.将值追加到列表中,只有当这个列表已经存在

RPUSHX key value
summary: Append a value to a list, only if the list exists
since: 2.2.0

redis list命令操作的更多相关文章

  1. Redis高级命令操作大全--推荐

    redis安装和使用 redis安装 wget http://download.redis.io/redis-stable.tar.gz tar zxvf redis-stable.tar.gz cd ...

  2. redis 简单命令操作

    一.概述: 在该系列的前几篇博客中,主要讲述的是与Redis数据类型相关的命令,如String.List.Set.Hashes和Sorted-Set.这些命令都具有一个共同点,即所有的操作都是针对与K ...

  3. Redis常用命令操作

    字符串类型: * 存储:set key value * 获取:get key * 无值返回nil * 删除:del key 哈希类型 hash: * 存储:hset key field value * ...

  4. Redis - 常用命令操作

    常用命令keys:        keys *        查看符合条件的所有key exists:        exists key    查看key是否存在 del:        del k ...

  5. 02 redis通用命令操作

    set hi hello 设置值 get hi 获取值 keys * 查询出所有的key memcached 不能查询出所有的key keys *h 模糊查找key keys h[ie] 模糊查找 k ...

  6. Redis客户端、服务端的安装以及命令操作

    目的: redis简介 redis服务端安装 redis客户端安装 redis相关命令操作 redis简介 官网下载(https://redis.io/) Redis 是完全开源免费的,遵守BSD协议 ...

  7. Redis操作Set工具类封装,Java Redis Set命令封装

    Redis操作Set工具类封装,Java Redis Set命令封装 >>>>>>>>>>>>>>>>& ...

  8. Redis操作List工具类封装,Java Redis List命令封装

    Redis操作List工具类封装,Java Redis List命令封装 >>>>>>>>>>>>>>>> ...

  9. Jedis对Redis的常用命令操作

    本篇主要总结一些Jedis对Redis的常用命令操作: 1.对key操作命令 2.对String操作命令 3.对List操作命令 4.对Set操作命令 5.对Hash操作命令 6.排序操作指令 一.项 ...

随机推荐

  1. leetCode之旅(14)-Number of 1 Bits

    题目描述: Write a function that takes an unsigned integer and returns the number of '1' bits it has (als ...

  2. Qt5中this application has requested the runtime to terminate it in an unusual way 无法运行问题的解决

    在windows平台使用Qt5.8mingw版写出的程序,在Qt中运行正常,而以release的形式编译并且补充完必要的dll文件后,在其他电脑上运行出现了以下问题: 经过查阅许多资料和亲身实验,终于 ...

  3. TCP浅谈为什么3次握手

    <计算机网络>中的例子是这样的,"已失效的连接请求报文段"的产生在这样一种情况:客户发出的第一个连接请求报文段并没有丢失,而是在某个网络结点长时间的滞留了,以致延误到连 ...

  4. 清楚css浮动的三种方法

    第一种:添加新元素,应用clear:both;  <div class="clear"></div> css样式:clear:both; 第二种:在浮动元素 ...

  5. nifi1.6.0汉化

    1.1 测试机 l  Apache NiFi 1.6.0 l  HDP 2.6.3 l  集群规模:单节点 l  操作系统:CentOs7 l  以下所有操作均在root用户下执行 1.2 安装环境 ...

  6. Python_@修饰器(装饰器)的理解

    装饰器本质上是一个Python函数,它可以让其他函数在不需要做任何代码变动的前提下增加额外功能. 装饰器的作用就是为已经存在的对象添加额外的功能. def funA(fun): print (fun( ...

  7. Vi 操作命令

    进入vi的命令  vi filename :打开或新建文件,并将光标置于第一行首  vi +n filename :打开文件,并将光标置于第n行首  vi + filename :打开文件,并将光标置 ...

  8. oracle to_date 函数

    update pamsodt0p10 set cursysdate =  to_date('2014-12-29 00:00:00','yyyy-mm-dd hh24:mi:ss') where cu ...

  9. jQuery监听事件经典例子

    关键字:jQuery监听事件经典例子  js代码:  ============================================================  $(function( ...

  10. 各种代码版本控制工具下使用http代理的方法

    原文:各种SCM工具下使用http代理下载源码:http://www.linuxeden.com/html/develop/20090723/66951.html SCM是软件配置管理的简称,常见的S ...