Redis全内存运行
在某些使用场景中,我们并不需要使用Redis的持久化,反而需要发挥redis的内存数据库特性,实现完全内存运行,达到需要的高性能。
在某些使用场景中,我们并不需要使用Redis的持久化,反而需要发挥redis的内存数据库特性,实现完全内存运行,达到需要的高性能。
Redis 本身支持持久化,通过在一定时间间隔或触发操作,将内存中的数据同步到磁盘来保证持久化。Redis 支持两种持久化方式,一种是 Snapshotting(快照),保存为dump.rdb文件,也是默认方式,另一种是 Append-only file(缩写aof)的方式,保存为 .aof 文件。
Snapshot 快照 通过save或者bgsave命令通知redis做一次快照持久化。save操作是在主线程中保存快照的,由于redis是用一个主线程来处理所有客户端的请求,这种方式会阻塞所有客户端请求。所以不推荐使用。另一点需要注意的是,每次快照持久化都是将内存数据完整写入到磁盘一次,并不是增量的只同步增量数据。如果数据量大的话,写操作会比较多,必然会引起大量的磁盘IO操作,可能会严重影响性能。
在默认的快照 rdb保存方式中,redis.conf 里面的配置如下
save 900 1 #900秒内如果超过1 个key 被修改,则发起快照保存
save 300 10 #300秒内容如超过10个key 被修改,则发起快照保存
save 60 10000
如果我们需要关闭快照,只需要将这几行注释了,然后重启 redis 即可。
如果是正在运行的实例,可以使用 redis-cli的命令
# 查看当前配置
config get save
# 关闭快照
config set save ""
来在线更新配置,输出OK表示设置成功。
AOF 比快照方式有更好的持久化性,是由于在使用aof 持久化方式时, redis 会将每一个收到的写
命令都通过write函数追加到文件中(默认是appendonly.aof) 。当redis 重启时会通过重新执行文件中
保存的写命令来在内存中重建整个数据库的内容
默认配置如下:
appendonly yes //启用日志追加持久化方式
#appendfsync always //每次收到写命令就立即强制写入磁盘,最慢的,但是保证完全的持久化,不推荐使用
appendfsync everysec //每秒钟强制写入磁盘一次,在性能和持久化方面做了很好的折中,,推荐
#appendfsync no //完全依赖操作系统,性能最好,持久化没保证
我们需要更新配置文件为:
appendfsync no
在线更新配置使用
# 查看当前配置
config get appendfsync
# 关闭快照
config set appendfsync no
通过这两个配置,redis就可以完全在内存运行。
如果想手动进行持久化,可以使用Redis的 bgsave 和 bgrewriteaof 来手动进行持久化。
Ubuntu 14.04下Redis安装及简单测试
Redis集群明细文档
Ubuntu 12.10下安装Redis(图文详解)+ Jedis连接Redis
Redis系列-安装部署维护篇
CentOS 6.3安装Redis
Redis安装部署学习笔记
Redis配置文件redis.conf 详解
Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里
本文永久更新链接地址:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.
