您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
Redis Spop 命令
发布时间:2021-11-02 22:00:56编辑:雪饮阅读()
Redis Spop 命令用于移除集合中的指定 key 的一个或多个随机元素,移除后会返回移除的元素。
127.0.0.1:6379> smembers key2
1) "e"
2) "a"
3) "d"
4) "c"
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379> spop key2
"a"
127.0.0.1:6379> smembers key2
1) "e"
2) "d"
3) "c"
127.0.0.1:6379> spop key2 2
1) "e"
2) "c"
127.0.0.1:6379> smembers key2
1) "d"
当集合不存在时,返回 nil 。
127.0.0.1:6379> keys *
1) "key4"
2) "key1"
3) "key2"
4) "key3"
127.0.0.1:6379> spop key4
(error) WRONGTYPE Operation against a key holding the wrong kind of value
127.0.0.1:6379> spop key4 1
(error) WRONGTYPE Operation against a key holding the wrong kind of value
127.0.0.1:6379> spop key4 2
(error) WRONGTYPE Operation against a key holding the wrong kind of value
当集合是空集时,返回 nil 。
127.0.0.1:6379> smembers key2
1) "d"
127.0.0.1:6379> spop key2
"d"
127.0.0.1:6379> spop key2
(nil)
关键字词:Redis,Spop
上一篇:Redis Smove 命令