Redis MSET 命令
发表于|更新于|Redis教程
|浏览量:
语法
1 | MSET key value [key value ...] |
可用版本
≥ 1.0.1
时间复杂度
$O(N)$
其中 N 是要设置的 key 的数量。
ACL类别
@write, @string, @slow
将给定的键设置为它们各自的值。MSET 用新的值替换现有的值,就像普通的 SET 一样。如果你不想覆盖现有的值,请参阅 MSETNX。
MSET 是原子性的,所以所有给定的键都是一次性设置的。也就是说,客户端不可能看到一些键被更新而另一些键没有变化。
返回值
总是返回 OK,因为 MSET 命令永远不会失败。
示例
1 | redis> MSET key1 "Hello" key2 "World" |
(END)
文章作者: Johnson Lin
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Johnson Lin!
相关推荐
2024-10-08
Redis Set SINTERCARD Command
The Redis SINTERCARD command returns the cardinality of the set which would result from the intersection of all the given sets. Keys that do not exist are considered to be empty sets. With one of the keys being an empty set, the resulting set is also empty (since set intersection with an empty set always results in an empty set). SyntaxThe basic syntax of the SINTERCARD command is as follows: 1SINTERCARD numkeys key [key ...] [LIMIT limit] This command is similar to SINTER, but instead of ret...
2024-10-02
Redis Set SADD Command
The Redis SADD command adds one or more member elements to a set. If an element already exists in the set, it will be ignored. If the set key does not exist, a new set is created with the added elements as its members. If the key is not of the set type, an error is returned. Note: In Redis version 2.4 and earlier, the SADD command only accepts a single member value. SyntaxThe basic syntax of the SADD command is as follows: 1SADD key member [member ...] Available SinceRedis version >= 1.0.0...
2023-06-09
Redis PFDEBUG 命令
语法1PFDEBUG subcommand key 可用版本 ≥ 2.8.9 时间复杂度 N/A ACL类别 @write, @hyperloglog, @admin, @slow, @dangerous PFDEBUG 命令是一个内部命令,用于开发和测试 Redis。 (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...
2023-06-04
Redis SETNX 命令
从 Redis 2.6.12 版本开始,此命令被标记为已废弃。在迁移或编写新的代码时,可以使用带有 NX 参数的 SET 命令替代。 语法1SETNX key value 可用版本 ≥ 1.0.0 时间复杂度 $O(1)$ ACL类别 @write, @string, @fast 如果 key 不存在,则将 key 设置为保存字符串值。在这种情况下,它等于 SET。当 key 已经存在时,则不执行任何操作。 SETNX 是 “SET if Not eXists” 的缩写。 返回值返回一个整数: 如果 key 被成功设置,则返回 1; 如果 key 没被设置,则返回 0 示例123456redis> SETNX john "JOHNSON"(integer) 1redis> SETNX john "JOHNSON LIN"(integer) 0redis> GET john"JOHNSON" (END)
2024-10-19
Redis Bitmaps
In Redis, a bitmap is a data structure that represents a sequence of bits (0s and 1s). Each bit in the bitmap can be either on (1) or off (0), allowing it to represent binary data in a compact form. This is particularly useful when you need to handle large sets of boolean data, as bitmaps allow you to store information in a very space-efficient way. For example, if you have a system tracking whether users have completed a daily task, a bitmap can efficiently store whether each user has comple...


