Redis(2.8.3) 命令学习 - Lists

BLPOP key [key ...] timeout

Remove and get the first element in a list, or block until one is available

More: http://redis.io/commands/blpophttp://www.redis.cn/commands/blpop.html

BRPOP key [key ...] timeout

Remove and get the last element in a list, or block until one is available

More: http://redis.io/commands/brpophttp://www.redis.cn/commands/brpop.html

BRPOPLPUSH source destination timeout

Pop a value from a list, push it to another list and return it; or block until one is available

More: http://redis.io/commands/brpoplpushhttp://www.redis.cn/commands/brpoplpush.html

LINDEX key index

Get an element from a list by its index

127.0.0.1:6379> LPUSH foo 1 3 5 7 9
(integer) 5
127.0.0.1:6379> LINDEX foo 1
"7"
127.0.0.1:6379> LINDEX foo -2
"3"

LINSERT key BEFORE|AFTER pivot value

Insert an element before or after another element in a list

127.0.0.1:6379> LPUSH foo 10 20 40 80
(integer) 4
127.0.0.1:6379> LINSERT foo BEFORE 20 80
(integer) 5
127.0.0.1:6379> LRANGE foo 0 -1
1) "80"
2) "40"
3) "80"
4) "20"
5) "10"
127.0.0.1:6379> LINSERT foo AFTER 80 0
(integer) 6
127.0.0.1:6379> LRANGE foo 0 -1
1) "80"
2) "0"
3) "40"
4) "80"
5) "20"
6) "10"

More: http://redis.io/commands/linserthttp://www.redis.cn/commands/linsert.html

LLEN key

Get the length of a list

127.0.0.1:6379> LPUSH foo 1 2 4
(integer) 3
127.0.0.1:6379> LLEN foo
(integer) 3

LPOP key

Remove and get the first element in a list

127.0.0.1:6379> LPUSH foo 1 2 4 8
(integer) 4
127.0.0.1:6379> LPOP foo
"8"
127.0.0.1:6379> LPOP foo
"4"

LPUSH key value [value ...]

Prepend one or multiple values to a list

127.0.0.1:6379> LPUSH foo 1
(integer) 1
127.0.0.1:6379> LPUSH foo 2 4
(integer) 3
127.0.0.1:6379> LRANGE foo -1 0
(empty list or set)
127.0.0.1:6379>
127.0.0.1:6379> LRANGE foo 0 -1
1) "4"
2) "2"
3) "1"

LPUSHX key value

Prepend a value to a list, only if the list exists

127.0.0.1:6379> LPUSHX foo 1
(integer) 0
127.0.0.1:6379> LRANGE foo 0 -1
(empty list or set)
127.0.0.1:6379> LPUSH foo 1
(integer) 1
127.0.0.1:6379> LPUSHX foo 2
(integer) 2
127.0.0.1:6379> LRANGE foo 0 -1
1) "2"
2) "1"

LRANGE key start stop

Get a range of elements from a list

127.0.0.1:6379> LPUSH foo 1 3 5 7 9
(integer) 5
127.0.0.1:6379> LRANGE foo 1 3
1) "7"
2) "5"
3) "3"
127.0.0.1:6379> LRANGE foo 0 -1
1) "9"
2) "7"
3) "5"
4) "3"
5) "1"

LREM key count value

Remove elements from a list

127.0.0.1:6379> RPUSH foo 1 2 1 3 1 4
(integer) 6
127.0.0.1:6379> LREM foo 2 1
(integer) 2
127.0.0.1:6379> LRANGE foo 0 -1
1) "2"
2) "3"
3) "1"
4) "4"
127.0.0.1:6379> RPUSH foo 3 1 3 2 1 3
(integer) 10
127.0.0.1:6379> LREM foo -3 3
(integer) 3
127.0.0.1:6379> LRANGE foo 0 -1
1) "2"
2) "3"
3) "1"
4) "4"
5) "1"
6) "2"
7) "1"
127.0.0.1:6379> LREM foo 0 1
(integer) 3
127.0.0.1:6379> LRANGE foo 0 -1
1) "2"
2) "3"
3) "4"
4) "2"

More: http://redis.io/commands/lremhttp://www.redis.cn/commands/lrem.html

LSET key index value

Set the value of an element in a list by its index

127.0.0.1:6379> RPUSH foo 1 2 3 4 5
(integer) 5
127.0.0.1:6379> LSET foo 3 0
OK
127.0.0.1:6379> LRANGE foo 0 -1
1) "1"
2) "2"
3) "3"
4) "0"
5) "5"

LTRIM key start stop

Trim a list to the specified range

127.0.0.1:6379> RPUSH foo 1 3 5 7 9
(integer) 5
127.0.0.1:6379> LTRIM foo 3 -1
OK
127.0.0.1:6379> LRANGE foo 0 -1
1) "7"
2) "9"

More: http://redis.io/commands/ltrimhttp://www.redis.cn/commands/ltrim.html

RPOP key

Remove and get the last element in a list

127.0.0.1:6379> RPUSH foo 1 2 3 4
(integer) 4
127.0.0.1:6379> RPOP foo
"4"
127.0.0.1:6379> RPOP foo
"3"
127.0.0.1:6379> LRANGE foo 0 -1
1) "1"
2) "2"

RPOPLPUSH source destination

Remove the last element in a list, prepend it to another list and return it

127.0.0.1:6379> RPUSH foo 1 3 5
(integer) 3
127.0.0.1:6379> RPUSH bar 2 4
(integer) 2
127.0.0.1:6379> RPOPLPUSH foo bar
"5"
127.0.0.1:6379> LRANGE foo 0 -1
1) "1"
2) "3"
127.0.0.1:6379> LRANGE bar 0 -1
1) "5"
2) "2"
3) "4"
127.0.0.1:6379> RPOPLPUSH bar bar
"4"
127.0.0.1:6379> LRANGE bar 0 -1
1) "4"
2) "5"
3) "2"

More: http://redis.io/commands/rpoplpushhttp://www.redis.cn/commands/rpoplpush.html

RPUSH key value [value ...]

Append one or multiple values to a list

127.0.0.1:6379> RPUSH foo 1
(integer) 1
127.0.0.1:6379> RPUSH foo 1 2 3
(integer) 4
127.0.0.1:6379> LRANGE foo 0 -1
1) "1"
2) "1"
3) "2"
4) "3"

RPUSHX key value

Append a value to a list, only if the list exists

127.0.0.1:6379> RPUSHX foo 1
(integer) 0
127.0.0.1:6379> LRANGE foo 0 -1
(empty list or set)
127.0.0.1:6379> RPUSH foo 1
(integer) 1
127.0.0.1:6379> RPUSHX foo 2
(integer) 2
127.0.0.1:6379> LRANGE foo 0 -1
1) "1"
2) "2"
时间: 2024-12-21 14:46:06

Redis(2.8.3) 命令学习 - Lists的相关文章

Redis(2.8.3) 命令学习 - Hashs

HDEL key field [field ...] Delete one or more hash fields 127.0.0.1:6379> HSET book.1 title helloworld (integer) 0 127.0.0.1:6379> HEXISTS book.1 title (integer) 1 127.0.0.1:6379> HDEL book.1 title (integer) 1 127.0.0.1:6379> HEXISTS book.1 ti

Redis(2.8.3) 命令学习 - Connection

AUTH password Authenticate to the server More: http://redis.io/commands/auth, http://www.redis.cn/commands/auth.html ECHO message Echo the given string 127.0.0.1:6379> ECHO "Hello World!" "Hello World!" More: http://redis.io/command

Redis(2.8.3) 命令学习 - Server

BGREWRITEAOF Asynchronously rewrite the append-only file BGSAVE Asynchronously save the dataset to disk CLIENT KILL [ip:port] [ID client-id] [TYPE normal|slave|pubsub] [ADDR ip:port] [SKIPME yes/no] Kill the connection of a client CLIENT LIST Get the

Redis(2.8.3) 命令学习 - Transactions

DISCARD Discard all commands issued after MULTI More: http://redis.io/commands/discard, http://www.redis.cn/commands/discard.html EXEC Execute all commands issued after MULTI More: http://redis.io/commands/exec, http://www.redis.cn/commands/exec.html

Redis(2.8.3) 命令学习 - Sorted Sets

ZADD key score member [score member ...] Add one or more members to a sorted set, or update its score if it already exists 127.0.0.1:6379> ZADD foo 1 one (integer) 1 127.0.0.1:6379> ZADD foo 2 two (integer) 1 127.0.0.1:6379> ZADD foo 3 three (int

Redis(2.8.3) 命令学习 - Pub/Sub

PSUBSCRIBE pattern [pattern ...] Listen for messages published to channels matching the given patterns PUBSUB subcommand [argument [argument ...]] Inspect the state of the Pub/Sub subsystem PUBLISH channel message Post a message to a channel PUNSUBSC

Redis 命令学习

每天不学习点新的东西,感觉就有点会被社会淘汰掉了.也许现在学习的知识会很快忘记,下次学习用到这个知识点的时候,再回来翻记录的笔记,我想这样会比从头再学,效率会高点吧. 闲话不多聊,回归正题.今天学习redis的命令,争取把常用的redis命令都敲一遍. redis命令就是在redi服务上执行的.要想启动redis服务.我是在windows本机上安装的redis.先切换到redis目录 然后启动redis服务. 启动redis redis-cli Redis 键(key) set key conm

sqlplus 命令学习

sqlplus 命令学习 $ sqlplus  / as sysdba SQL> help index 可以输入sqlplus 命令 Enter Help [topic] for help. @             COPY         PAUSE                    SHUTDOWN @@            DEFINE       PRINT                    SPOOL /             DEL          PROMPT  

Redis介绍及常用命令

Redis介绍及常用命令 Redis是一个key-value存储系统.和Memcached类似,但是解决了断电后数据完全丢失的情况,而且她支持更多无化的value类型,除了和string外,还支持lists(链表).sets(集合).zsets(有序集合).Hashes(哈希表)几种数据类型.这些数据类型都支持push/pop.add/remove及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的. 博客分类: NoSql---Redis nosqlredis 一 Redis介绍 Red