恢复
Syntax
RESTORE key ttl serialized-value [REPLACE] [ABSTTL] [IDLETIME seconds] [FREQ frequency]
- Available since:
- 2.6.0
- Time complexity:
- O(1) to create the new key and additional O(N*M) to reconstruct the serialized value, where N is the number of Redis objects composing the value and M their average size. For small string values the time complexity is thus O(1)+O(1*M) where M is small, so simply O(1). However for sorted set values the complexity is O(N*M*log(N)) because inserting values into sorted sets is O(log(N)).
- ACL categories:
-
@keyspace
,@write
,@slow
,@dangerous
,
创建一个与通过反序列化提供的序列化值(通过DUMP
获得)相关联的键。
如果ttl
为0,则创建的键没有任何过期时间,否则将设置指定的过期时间(以毫秒为单位)。
如果使用了ABSTTL
修饰符,ttl
应表示一个绝对的Unix时间戳(以毫秒为单位),在此时间戳之后键将过期。
出于驱逐目的,您可以使用IDLETIME
或FREQ
修饰符。有关更多信息,请参见OBJECT
。
RESTORE
在 key
已经存在时会返回“目标键名正忙”错误,除非你使用 REPLACE
修饰符。
RESTORE
检查 RDB 版本和数据校验和。
如果不匹配,则返回错误。
示例
redis> DEL mykey
0
redis> RESTORE mykey 0 "\n\x17\x17\x00\x00\x00\x12\x00\x00\x00\x03\x00\
x00\xc0\x01\x00\x04\xc0\x02\x00\x04\xc0\x03\x00\
xff\x04\x00u#<\xc0;.\xe9\xdd"
OK
redis> TYPE mykey
list
redis> LRANGE mykey 0 -1
1) "1"
2) "2"
3) "3"
RESP2/RESP3 回复
Simple string reply:OK
.
历史
- 从 Redis 3.0.0 版本开始:添加了
REPLACE
修饰符。 - 从Redis版本5.0.0开始:添加了
ABSTTL
修饰符。 - 从 Redis 5.0.0 版本开始:添加了
IDLETIME
和FREQ
选项。