麻烦各位帮忙解读一个命令参数关于 Redis 的

使用redis 创建key 的命令 set($key, $value, $expireResolution = null, $expireTTL = null, $flag = null) 中参数都是什么意思呢? 主要是 expireResolution expireTTL flag

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

expireResolution 是过期策略,比如

  • EX seconds -- Set the specified expire time, in seconds. 秒
  • PX milliseconds -- Set the specified expire time, in milliseconds. 毫秒
  • NX -- Only set the key if it does not already exist. 不存在则设置
  • XX -- Only set the key if it already exist. 存在则设置

expireTTL 过期时间

4年前 评论
讨论数量: 5

expireResolution 是过期策略,比如

  • EX seconds -- Set the specified expire time, in seconds. 秒
  • PX milliseconds -- Set the specified expire time, in milliseconds. 毫秒
  • NX -- Only set the key if it does not already exist. 不存在则设置
  • XX -- Only set the key if it already exist. 存在则设置

expireTTL 过期时间

4年前 评论

过期时间,用predis跟phpredis,这个值会不一样

4年前 评论

github.com/ProgerXP/predis-doc/blo...

描述信息: set($key, $value[, $option[...]]) Set the string value of a key. Options are given inline and can be:

'EX', seconds 'PX', ms 'NX' or 'XX'

我的demo: app('redis')->set($key, $value, 'EX',100);

2年前 评论

我找到了一个 predis 的 issue:

github.com/predis/predis/issues/64...

set ($key, $value, $expireResolution = null, $expireTTL = null, $flag = null)

$expireResolution 取值为 ex | px

$expireTTL 取值为过期时间,当 $expireResolution 为 ex 时,该值的单位为秒;为 px 时单位为毫秒

$flag nx 不存在时才设定,xx 存在时设定

$redis->set($key, $value, "ex", 60, "nx"); 

相当于执行 redis 的以下命令:

SET $key $value ex 60 nx
9个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!