当前位置:网站首页>Redis 内存占满导致的 Setnx 命令执行失败
Redis 内存占满导致的 Setnx 命令执行失败
2022-04-23 09:30:00 【潘广宇 de 小白笔记】
一、问题发生
正常情况下,通过 setnx 设置的一个锁,应该会1s后过期(防止并发请求,处理相同逻辑),但是实际发生的情况是,第一次处理下面的逻辑,就抛出异常。说明 setnx 函数返回了 false。
$redis_key_lock = 'lock';
//@todo 设置了一个1s的锁
$lock = $redis->setnx($redis_key_lock, 1);
//@todo 锁将会在1s后过期
$redis->expire($redis_key_lock, 1);
if ($lock) {
// 执行其他逻辑
} else {
throw new \Exception("锁存在");
}
二、问题排查
redis 的内存占用满了

通过 redis.conf 查看一下 redis 过期策略
# maxmemory-policy volatile-lru
说明 redis 使用了默认的过期策略 noeviction
默认的过期策略 noeviction 不会对过期的 keys 做任何清理,当内存占用满后,会拒绝执行所有的写操作,通过翻阅redis配置文件,可以查到相关提示,并且除了 setnx,其他的写操作相关指令,都会执行失败。

解决方案就是快速释放 redis 内存,让 setnx 命令可以正常执行。
版权声明
本文为[潘广宇 de 小白笔记]所创,转载请带上原文链接,感谢
https://panguangyu.blog.csdn.net/article/details/124341363
边栏推荐
- NPM installation yarn
- 搞不懂时间、时间戳、时区,快来看这篇
- Data visualization: use Excel to make radar chart
- golang力扣leetcode 396.旋转函数
- DVWA range practice record
- Summary of common concepts and problems of linear algebra in postgraduate entrance examination
- ALV树(LL LR RL RR)插入删除
- Number of islands
- 501. Mode in binary search tree
- Failed to download esp32 program, prompting timeout
猜你喜欢

Using JS to realize a thousandth bit
![Sql1 [geek challenge 2019]](/img/ad/afca09bc1da003393319af700e90e3.png)
Sql1 [geek challenge 2019]

错题汇总1

Leetcode0587. 安装栅栏(difficult)

Write down the post order traversal of the ~ binary tree

机器学习(六)——贝叶斯分类器

Kettle experiment (III)

Distributed message oriented middleware framework selection - Digital Architecture Design (7)

Emuelec compilation summary

GoLand debug go use - white record
随机推荐
Learn FPGA (from Verilog to HLS)
On array replication
Your guide to lowering your cholesterol with TLC (continuously updated)
The most concerned occupations after 00: civil servants ranked second. What was the first?
Using JS to realize a thousandth bit
Leetcode-199 - right view of binary tree
Sql1 [geek challenge 2019]
JS prototype chain
npm ERR! network
GUI, CLI and UNIX Philosophy
JS DOM learn three ways to create elements
DVWA range practice
SQL used query statements
108. 将有序数组转换为二叉搜索树
如何实现根据照片获取地理位置及如何防御照片泄漏地理位置
Thread scheduling (priority)
Colorui solves the problem of blocking content in bottom navigation
基于ThinkPHP5版本TRC20-资金归集解决方案
MySQL of database -- Fundamentals
Exclusive thoughts and cases of JS