search
HomeDatabaseMysql TutorialRedis内存使用达到maxmemory设定值后玩家数据无法写入解决

先说说我们公司这边的redis应用场景。目前线上的游戏是采用redis作为MongoDB的前端缓存,存储一些玩家需要经常访问的数据,同时游

先说说我们公司这边的redis应用场景。目前线上的游戏是采用redis作为MongoDB的前端缓存,存储一些玩家需要经常访问的数据,同时游戏的运营公告信息以及BI相关采集数据也存放在redis中。在上周五,运营同事反映在某个合作方的游戏后台添加了游戏运营公告,但是进入游戏后却无法看到公告更新。同时,也有玩家反映游戏相关的活动奖励,游戏排行榜等信息没有更新。通过和开发同事沟通,初步判断是redis无法写入的问题。由于合作方之前一直没有提供redis服务器的访问权限,只有redis实例的权限。通过查看之前让合作方运维同事提供的redis配置参数,发现他们设置了maxmemory 2G 限定了单个redis实例最大使用内存为2G。我勒个去,这个坑可大了,由于之前对redis运维方面没有作深入研究,也没有仔细核对对方运维的redis配置参数。结果这次就坑大了。我们有接近10个区的数据都写入了这个实例中。再进入redis实例中,使用info 命令查看used_memory_human:1.98G 差不多达到了最大值,难怪更新了后台公告,游戏内却无法显示。然后联系对方运维调整maxmemory参数,一切恢复正常,运营那边又得制定玩家赔偿方案了。

redis的相关配置参考信息直接可以通过redis.conf文件查看,在这个文件中关于redis的常规配置已经解释得比较清楚了。这里主要讲解一下maxmemory相关的说明。

如果设定了maxmemory,使用redis的时候,redis的内存使用量不能超过设定的值,一旦redis的内存使用量达到了最大值,redis将会尝试按照选择的eviction policy(回收策略)移除相应的keys

如果redis不能根据回收策略移除keys,或者回收策略设置成noeviction,那么redis将对需要写操作的命令返回错误信息,如SET,LPUSH操作,对GET这样的只读操作会继续响应。

在redis.conf中给出了一个警告信息,如果一个设置了maxmemory的实例连接了从redis,,那么预留给redis使用的内存除了redis实例本身占用的内存外还要加上用于主从复制的输出缓冲区大小(the output buffers need to feed the slaves),这样,才不会触发移除keys的死循环,因为当内存达到最大内存限制后,会根据eviction policy移除相应的keys,这时,从redis也会同步移除keys操作,最终所有数据都被清空。

总之,一句话,对一个连接了从redis的redis实例设置maxmemory时,建议设置一个较高的值,使系统有多余的内存用于主从同步,当然,如果eviction policy设置成noevcition,则不需要这么设置。

Ubuntu 14.04下Redis安装及简单测试

Redis集群明细文档

Ubuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis

Redis系列-安装部署维护篇

CentOS 6.3安装Redis

Redis安装部署学习笔记

Redis配置文件redis.conf 详解

Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里

本文永久更新链接地址:

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

How do you handle large datasets in MySQL?How do you handle large datasets in MySQL?Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you drop a table in MySQL using the DROP TABLE statement?How do you drop a table in MySQL using the DROP TABLE statement?Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you represent relationships using foreign keys?How do you represent relationships using foreign keys?Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

How do you create indexes on JSON columns?How do you create indexes on JSON columns?Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.