当前位置:网站首页>Difference between redis setex and set
Difference between redis setex and set
2022-04-22 12:11:00 【m0_ sixty million seven hundred and twenty-one thousand five hu】
SETEX command Redis character string (String) command
SETEX key seconds value
take value Related to key, And will key The lifetime of is set to seconds( In seconds ).
If key Already exist ,SETEX The old value will be overwritten ;
This command is similar to the following two commands :
$redis->SET('key', 'value');
$redis->EXPIRE('key','seconds'); # Set the lifetime
Here's the difference ,SETEX It's an atomicity (atomic) operation , The actions of association value and set lifetime will be completed in the same time , The command is in Redis When used as a cache , Very practical .
Return value :
When the setting is successful, return OK.
When seconds When the parameter is illegal , Return an error .
# situation 1:key non-existent
$redis->SETEX('cache_user_id', 60,100001);//bool(true)
echo $redis->GET('cache_user_id'); # value //"100001"
echo $redis->TTL('cache_user_id'); # Remaining time to live //int(56)
# situation 2:key Already exist ,key overwritten
$redis->SET('cd', "timeless"); //bool(true);
$redis->SETEX('cd', 3000,"goodbye my love"); //bool(true);
echo $redis->GET('cd');//"goodbye my love"
版权声明
本文为[m0_ sixty million seven hundred and twenty-one thousand five hu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221206565587.html
边栏推荐
- 【深入理解TcaplusDB技术】读取列表指定位置数据接口说明——[List表]
- JS [detailed] scope
- 低频(LF)RFID 智能终端
- 影响软件质量的几个因素
- congratulations! You have been concerned about the official account for 1 years, and invite you to join NetEase data analysis training.
- ThreadLocal
- Set the sliding wheel in vscode to change the font size
- 开发者友好型公链Neo | 如何连接 Web2 开发者到 Web3 世界
- 电路实验——实验四 戴维南定理与诺顿定理
- Distributed transaction and lock
猜你喜欢

14天玩转51单片机第二天——以为咱们在玩LED灯?不不不,咱们在玩底层的输入输出^-^

电工第一讲

NFT, gamefi, socialfi, cloud storage, dfinity, the hottest track in ecology

2. Flddler response shows the solution to the problem of garbled code

In depth analysis of the drawing source code process of view

UML总结

congratulations! You have been concerned about the official account for 1 years, and invite you to join NetEase data analysis training.

"Open source summer" activity is hot. In the registration, rich bonuses are waiting for you to get!

A note that allows you to capture the offer of a large factory. Come and get it quickly

Redis新版本发布,你还认为Redis是单线程?
随机推荐
LeetCode454. Four number addition II
离职的互联网人,都去哪儿了?
zuul使用中的一些问题
“Stack Overflow中文内容”终于来了!邀您体验反馈拿好礼
低频(LF)RFID 智能终端
哇哦,好丰富呀。
LeetCode383. Ransom letter
记一次内网渗透靶场学习
Software intelligence: the AI service function of AAAS system: the relationship between the unconscious agent function of outline map and gossip map
2. Flddler response shows the solution to the problem of garbled code
Walking in the clouds - all my life
LeetCode383. 赎金信
Father of MySQL: the code should be written at once, not later
LeetCode202. Happy number
Complete introductory tutorial of R language hypothesis testing
Codeforces Round #783 (Div. 2)
Implementation and principle analysis of synchronized
UML summary
深入解析View的绘制源码流程
Chapter 1 Introduction