Redis SETEX 命令
Created|Updated|Redis教程
|Post Views:
从 Redis 2.6.12 版本开始,此命令被标记为已废弃。
在迁移或编写新的代码时,可以使用带有EX参数的SET命令替代。
语法
1 | SETEX key seconds value |
可用版本
≥ 2.0.0
时间复杂度
$O(1)$
ACL类别
@write, @string, @slow
设置 key 以保存字符串值,并将 key 设置为在给定的秒数后过期。此命令等效于:
1 | SET key value EX seconds |
当秒数无效时,返回错误。
返回值
如果正确执行,则返回 OK。
示例
1 | redis> SETEX tt_key 1000 "JOHNSON" |
(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
2024-11-09
Redis HyperLogLog PFDEBUG Command
SyntaxThe basic syntax of the PFDEBUG command is as follows: 1PFDEBUG subcommand key The PFDEBUG command is an internal command. It is meant to be used for developing and testing Redis. Available SinceVersion 2.8.9 or later. Time ComplexityN/A ACL Categories@write, @hyperloglog, @admin, @slow, @dangerous
2024-10-09
Redis Set SISMEMBER Command
The Redis SISMEMBER command checks if a given element is a member of the set. SyntaxThe basic syntax of the SISMEMBER command is as follows: 1SISMEMBER key member It returns if member is a member of the set stored at key. Available SinceRedis version >= 1.0.0 Time ComplexityO(1) ACL Categories@read, @set, @fast Return Value 0 if the element is not a member of the set, or when the key does not exist. 1 if the element is a member of the set. Example123456127.0.0.1:6379> SADD key1 a b c d...
2023-06-03
Redis INCRBY 命令
语法1INCRBY key increment 可用版本 ≥ 1.0.0 时间复杂度 $O(1)$ ACL类别 @write, @string, @fast 将 key 中储存的数字加上指定的增量值。如果键不存在,则在执行操作前将其设置为 0。如果键包含一个错误类型的值或包含一个不能表示为整数的字符串,则返回错误。 该操作仅限于 64 位有符号的整数。 返回值返回一个整数,表示加上指定的增量值之后的 key 值。 示例 1以下例子演示了使用 INCRBY 命令对一个存储整数值的键进行加 2 操作: 12345redis> SET counter "1000"OKredis> INCRBY counter 2(integer) 1002redis> 示例 2对一个不存在的键进行 INCRBY 操作: 1234567redis> EXISTS total(integer) 0redis> INCRBY total 5(integer) 5redis> GET total"5"redis> 示例 3对一...
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-11-08
Redis HyperLogLog PFMERGE Command
The Redis PFMERGE command merges multiple HyperLogLogs into a single HyperLogLog. The cardinality estimate of the resulting HyperLogLog is calculated by taking the union of all the given HyperLogLogs. SyntaxThe basic syntax of the PFMERGE command is as follows: 1PFMERGE destkey [sourcekey [sourcekey ...]] The command merges multiple HyperLogLog values to approximate the cardinality of the union of the observed sets. The result is stored in a destination variable, which is created if it doesn’...
2024-10-06
Redis Set SINTER Command
The Redis SINTER command returns the members of the set resulting 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). For example: 1234key1 = {a,b,c,d}key2 = {c}key3 = {a,c,e}SINTER key1 key2 key3 = {c} SyntaxThe basic syntax of the SINTER command is as follow...