ValueOperations接口的void set(K key, V value, long timeout, TimeUnit unit)方法

文档地址 https://docs.spring.io/spring-data/redis/docs/current/api/org/springframework/data/redis/core/ValueOperations.html#set(K,V)

set

void set(K key, V value, long timeout, TimeUnit unit)

设置键的值和过期超时时间。
Set the value and expiration timeout for key.

Parameters:

  • key - must not be null.
  • value - must not be null.
  • timeout - the key expiration timeout.
  • unit - must not be null.

See Also: Redis Documentation: SETEX https://redis.io/docs/latest/commands/setex/

示例

stringRedisTemplate.opsForValue().set(LOGIN_CODE_KEY + phone, code, LOGIN_CODE_TTL, TimeUnit.MINUTES);
posted @ 2025-04-11 20:45  kuki'  阅读(45)  评论(0)    收藏  举报