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-07-25
How to learn Redis effectively?
Redis, an open-source, high-performance in-memory data structure store, is renowned for its speed, versatility, and simplicity. It has gained immense popularity and is widely utilized for caching, distributed locks, session management, real-time analytics, and more. Whether you’re a developer looking to expand your skills or an IT professional aiming to optimize data handling, mastering Redis can significantly enhance your proficiency. Here’s a comprehensive guide on how to learn Redis effect...
2024-11-15
Introduction to Redis Bitmaps
Bitmaps are not an actual data type, but a set of bit-oriented operations defined on the String type which is treated like a bit vector. Since strings are binary safe blobs and their maximum length is 512 MB, they are suitable to set up to 2^32 different bits. You can perform bitwise operations on one or more strings. Some examples of bitmap use cases include: Efficient set representations for cases where the members of a set correspond to the integers 0-N. Object permissions, where each bit...
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...
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-07-27
Flushing Cache Data in Redis: A Step-by-Step Guide
Caching mechanisms are vital for optimizing application performance by storing frequently accessed data in-memory. Redis, as a robust key-value store, offers powerful caching capabilities. Occasionally, you might need to clear or flush all cached data from Redis to ensure consistency or during maintenance tasks. Here’s how you can do it effectively: Understanding Redis FlushingFlushing in Redis refers to the action of removing all data stored in the current database. This operation is irreve...
2024-11-03
Redis HyperLogLog
HyperLogLog is a probabilistic data structure used to estimate the cardinality of a set. As a probabilistic data structure, HyperLogLog trades perfect accuracy for efficient space utilization. Redis added the HyperLogLog data structure in version 2.8.9. HyperLogLog in Redis is an algorithm used for cardinality estimation. Its main advantage is that, even when the number of input elements is extremely large, the memory required to calculate the cardinality remains fixed and small. In Redis, ...


