redis持久化-纯缓存模式

发布于:2025-07-05 ⋅ 阅读:(15) ⋅ 点赞:(0)

redis持久化-纯缓存模式

文档

  1. redis单机安装
  2. redis常用的五种数据类型
  3. redis数据类型-位图bitmap
  4. redis数据类型-基数统计HyperLogLog
  5. redis数据类型-地理空间GEO
  6. redis数据类型-流Stream
  7. redis数据类型-位域bitfield
  8. redis持久化-RDB
  9. redis持久化-AOF
  10. redis持久化-RDB+AOF混合模式

官方文档

  1. 官网操作命令指南页面:https://redis.io/docs/latest/commands/?name=get&group=string
  2. Redis persistence

说明

  1. redis版本:7.0.0

纯缓存模式

支持No persistence模式
  1. 官方说明:Redis persistence

    Persistence refers to the writing of data to durable storage, such as a solid-state disk (SSD). Redis provides a range of persistence options. These include:

    • RDB (Redis Database): RDB persistence performs point-in-time snapshots of your dataset at specified intervals.
    • AOF (Append Only File): AOF persistence logs every write operation received by the server. These operations can then be replayed again at server startup, reconstructing the original dataset. Commands are logged using the same format as the Redis protocol itself.
    • No persistence: You can disable persistence completely. This is sometimes used when caching.
    • RDB + AOF: You can also combine both AOF and RDB in the same instance.
禁用RDB持久化
  1. 找到启动服务使用的配置文件,通常将安装目录下的redis.conf复制到指定路径做为启动文件,下面是配置文件中SNAPSHOTTING配置的相关介绍

    ################################ SNAPSHOTTING  ################################
    
    # Save the DB to disk.
    #
    # save <seconds> <changes> [<seconds> <changes> ...]
    #
    # Redis will save the DB if the given number of seconds elapsed and it
    # surpassed the given number of write operations against the DB.
    #
    # Snapshotting can be completely disabled with a single empty string argument
    # as in following example:
    #
    # save ""
    #
    # Unless specified otherwise, by default Redis will save the DB:
    #   * After 3600 seconds (an hour) if at least 1 change was performed
    #   * After 300 seconds (5 minutes) if at least 100 changes were performed
    #   * After 60 seconds if at least 10000 changes were performed
    #
    # You can set these explicitly by uncommenting the following line.
    #
    # save 3600 1 300 100 60 10000
    
    save ""
    
  2. 根据规则,可以使用单个空字符串参数完全禁用快照,即save ""

  3. RDB持久化模式默认是开启的,需将配置手动调整为save ""

  4. 修改后重启redis

  5. 禁用RDB持久化是禁用了自动触发,仍然可以使用SAVEBGSAVE等命令手动生成rdb文件

禁用AOF持久化
  1. 找到启动服务使用的配置文件,通常将安装目录下的redis.conf复制到指定路径做为启动文件,下面是配置文件中APPEND ONLY MODE配置的相关介绍

    ############################## APPEND ONLY MODE ###############################
    
    # By default Redis asynchronously dumps the dataset on disk. This mode is
    # good enough in many applications, but an issue with the Redis process or
    # a power outage may result into a few minutes of writes lost (depending on
    # the configured save points).
    #
    # The Append Only File is an alternative persistence mode that provides
    # much better durability. For instance using the default data fsync policy
    # (see later in the config file) Redis can lose just one second of writes in a
    # dramatic event like a server power outage, or a single write if something
    # wrong with the Redis process itself happens, but the operating system is
    # still running correctly.
    #
    # AOF and RDB persistence can be enabled at the same time without problems.
    # If the AOF is enabled on startup Redis will load the AOF, that is the file
    # with the better durability guarantees.
    #
    # Please check https://redis.io/topics/persistence for more information.
    
    appendonly no
    
  2. appendonly设置为no,表示禁用AOF持久化,默认值即为no

  3. AOF持久化模式默认是禁用的

  4. 修改后重启redis