Redis MGET 命令
发表于|更新于|Redis教程
|浏览量:
语法
1 | MGET key [key ...] |
可用版本
≥ 1.0.0
时间复杂度
$O(N)$
其中 N 是要检索的 key 的数量。
ACL类别
@read, @string, @fast
返回所有指定 key 的值。对于每个不持有字符串值或不存在的键,将返回特殊值 nil。正因为如此,该操作永远不会失败。
返回值
返回一个数组,元素由所有给定的 key 上的值组成。
示例
1 | redis> SET key1 "Hello" |
(END)
文章作者: Johnson Lin
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Johnson Lin!
相关推荐
2023-06-04
Redis SUBSTR 命令
从 Redis 2.0.0 版本开始,此命令被标记为已废弃。在迁移或编写新的代码时,可以使用 GETRANGE 命令替代。 语法1SUBSTR key start end 可用版本 ≥ 1.0.0 时间复杂度 $O(N)$ 其中 N 是返回字符串的长度。复杂度最终是由返回的长度决定的,但是由于从现有的字符串中创建一个子串的代价是非常低的,对于小的字符串可以认为是 $O(1)$。 ACL类别 @read, @string, @slow 返回存储在 key 中的字符串值的子串,由偏移量 start 和 end 决定(两者均包括在内)。负的偏移量可以用来提供一个从字符串的末尾开始的偏移量。所以 -1 表示最后一个字符,-2 表示倒数第二个,以此类推。 该命令通过将结果范围限制为字符串的实际长度来处理超出范围的请求。 返回值返回存储在 key 中的字符串值的子串。 示例 112345redis> SET user "JOHNSON LIN"OKredis> SUBSTR user 1 2"OH" 示例 2使用负的偏移量: 1234...
2023-06-04
Redis SETEX 命令
从 Redis 2.6.12 版本开始,此命令被标记为已废弃。在迁移或编写新的代码时,可以使用带有 EX 参数的 SET 命令替代。 语法1SETEX key seconds value 可用版本 ≥ 2.0.0 时间复杂度 $O(1)$ ACL类别 @write, @string, @slow 设置 key 以保存字符串值,并将 key 设置为在给定的秒数后过期。此命令等效于: 1SET key value EX seconds 当秒数无效时,返回错误。 返回值如果正确执行,则返回 OK。 示例123456redis> SETEX tt_key 1000 "JOHNSON"OKredis> TTL tt_key(integer) 1000redis> GET tt_key"JOHNSON" (END)
2023-06-04
Redis MSETNX 命令
语法1MSETNX key value [key value ...] 可用版本 ≥ 1.0.1 时间复杂度 $O(N)$ 其中 N 是要设置的 key 的数量。 ACL类别 @write, @string, @slow 将给定的键设置为其各自的值。但只要有一个键已经存在,MSETNX 就不会执行任何操作。 由于这种语义,可以使用 MSETNX 来设置代表唯一逻辑对象的不同字段的不同键,以确保设置所有字段或根本不设置任何字段。 MSETNX 是原子的,所以所有给定的键都是一次性设置的。也就是说,客户端不可能看到一些键被更新,而另一些键却没有变化。 返回值返回一个整数,具体而言: 1 - 如果所有的键都被设置了,则返回 1; 0 - 如果没有设置任何键(至少有一个键已经存在),则返回 0。 示例12345678redis> MSETNX key1 "Hello" key2 "there"(integer) 1redis> MSETNX key2 "new" key3 "world"(i...
2024-10-15
Redis Set SREM Command
The Redis SREM command removes one or more members from a set. Non-existent members are ignored. An error is returned if the key is not of set type. SyntaxThe basic syntax of the SREM command is as follows: 1SREM key member [member ...] In Redis version 2.4 and earlier, SREM only accepted a single member value. Available SinceRedis version >= 1.0.0 Time ComplexityO(N) where N is the number of members to be removed. ACL Categories@write, @set, @fast Return ValueReturns the number of members...
2024-06-02
Using the PFADD Command in Redis
Redis, an open-source, in-memory data structure store, offers a wide range of commands to manipulate data structures like strings, lists, sets, hashes, bitmaps, hyperloglogs, and more. Among these, the HyperLogLog data type is particularly useful for approximating the number of unique elements in a set when the set is too large to fit into memory or when you don’t need absolute accuracy. The PFADD command is one of the key operations for working with HyperLogLog in Redis. This guide will show...
2024-10-12
Redis Set SMOVE Command
The Redis SMOVE command moves the specified member element from the source set to the destination set. SMOVE operation is an atomic. If the source set does not exist or does not contain the specified member, the command does nothing and returns 0. Otherwise, the member is removed from the source set and added to the destination set. If the destination set already contains the member, the SMOVE command simply removes the member from the source set without adding it to the destination set again...


