当前位置:网站首页>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
边栏推荐
- Three ways to create objects in JS
- Project upload part
- Leetcode0587. 安装栅栏(difficult)
- Go language learning notes - exception handling | go language from scratch
- 考研线性代数常见概念、问题总结
- Simple understanding of arguments in JS
- Your guide to lowering your cholesterol with TLC (continuously updated)
- Kettle experiment
- Go language learning notes - slice, map | go language from scratch
- JS case to find the maximum value, reverse the array, bubble sort
猜你喜欢
108. Convert an ordered array into a binary search tree
《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路
[C language] document operation
node安装
Production practice elk
How to obtain geographical location based on photos and how to prevent photos from leaking geographical location
653. 两数之和 IV - 输入 BST
DVWA range practice record
Acquisition of DOM learning elements JS
Three challenges that a successful Devops leader should be aware of
随机推荐
golang力扣leetcode 396.旋转函数
Group Backpack
MySQL of database -- Fundamentals
Two declaration methods of functions of JS
2D 01 Backpack
JS node operation, why learn node operation
【SQL server速成之路】数据库的视图和游标
[SQL Server fast track] view and cursor of database
JS prototype chain
ASUS laptop can't read USB and surf the Internet after reinstalling the system
【读书笔记】《Verilog数字系统设计教程》 第5章 条件语句、循环语句和块语句(附思考题答案)
员工试用期转正申请书(泸州老窖)
EmuElec 编译总结
Flink SQL realizes the integration of stream and batch
kernel-pwn学习(3)--ret2user&&kernel ROP&&QWB2018-core
Emuelec compilation summary
GoLand debug go use - white record
STM32 and FreeRTOS stack parsing
NLLLoss+log_ SoftMax=CE_ Loss
Distributed message oriented middleware framework selection - Digital Architecture Design (7)