Redis MSET 命令
Created|Updated|Redis教程
|Post Views:
语法
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)
Author: Johnson Lin
Copyright Notice: All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.
Related Articles
2019-09-03
Redis根据通配符批量删除Key
Redis 目前还不支持根据通配符批量删除 Key 的命令,但我们可以借助 Redis 的 del 命令、Linux 管道和 xargs 指令来完成。 Redis的 del 命令支持删除给定的一个或多个 key,并返回被删除 key 的数量。如命令 del key1 key2 key3。 比如要删除所有以 WxMpSessionKey 开头的 Key,可以使用如下命令: 12[redis@iztz9ploifbvce ~]# redis-cli -h 192.168.182.227 -p 1379 keys "WxMpSessionKey*" |xargs redis-cli -h 192.168.182.227 -p 1379 del(integer) 2674 如果连接 Redis 的 HOST 为 127.0.0.1,端口号也为默认的 6379,则以上的命令可以简写为: 1redis-cli keys "WxMpSessionKey*" |xargs redis-cli del (END)
2019-12-19
Spring Boot 2.x 集成Redis示例
一、如何集成首先,在 pom 文件新增 redis 依赖: 1234<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId></dependency> 接着修改项目配置文件 application.properties,增加 redis 配置 1234# redis hostspring.redis.host=172.24.58.226# redis portspring.redis.port=6379 经过上面简单的两步,即可在项目中使用 StringRedisTemplate 和 RedisTemplate<Object,Object>,因为从 Spring Boot 2.0 开始,Spring...
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...
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...
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...
2024-07-30
Effective Ways to Delete Fuzzy Matching Keys in Redis
In Redis, managing keys efficiently is crucial for optimal performance. Sometimes, you might need to delete keys that match a pattern or have a fuzzy match. Here’s how you can achieve this: Using Redis CLI CommandsRedis CLI provides several commands to interact with keys. To delete keys that match a pattern, you can use the KEYS command in combination with the DEL command: 1redis-cli KEYS "pattern*" | xargs redis-cli DEL Replace "pattern*" with your specific pattern. This...