Redis详解(七)进阶:Redis.conf配置文件

Redis.conf配置文件

  • 容量单位不区分大小写

    # 1k => 1000 bytes
    # 1kb => 1024 bytes
    # 1m => 1000000 bytes
    # 1mb => 1024*1024 bytes
    # 1g => 1000000000 bytes
    # 1gb => 1024*1024*1024 bytes
    #
    # units are case insensitive so 1GB 1Gb 1gB are all the same.
    
  • 可以包含多个配置文件

    ################################## INCLUDES ###################################
    # include /path/to/local.conf
    # include /path/to/other.conf
    
  • 网络配置

    ################################## NETWORK #####################################
    bind 127.0.0.1   //ip绑定
    protected-mode yes //开启保护模式
    port 6379  //端口号
    
  • 通用配置 GENERAL

    ################################# GENERAL #####################################
    daemonize yes   //以守护进程的方式运行,默认no, 需要自己开启
    pidfile /www/server/redis/redis.pid   //如果以后台方式运行,就需要指定一个pid文件
        
    # Specify the server verbosity level.
    # This can be one of:
    # debug (a lot of information, useful for development/testing)  #调试(大量信息,对开发/测试有用)
    # verbose (many rarely useful info, but not a mess like the debug level)  #冗长(许多很少有用的信息,但不像调试级别那样混乱)
    # notice (moderately verbose, what you want in production probably)  #注意(适度冗长,可能在生产中需要什么)
    # warning (only very important / critical messages are logged)   #警告(只记录非常重要/关键的消息)
    loglevel notice  //日志级别
        
    logfile "/www/server/redis/redis.log"  //日志输出文件
        
    databases 16   //数据库数量,默认16个
    always-show-logo yes  //是否显示log
    
  • 快照

    因为是内存数据库,没有持久化,那么数据库断电即失去

    持久化,表示在规定的时间内,执行了多少操作,则会持久化文件 .rdb .aof

    ################################ SNAPSHOTTING  ################################
    save 900 1  #表示在900s内,如果至少有一个key发生了变化,我们就进行持久化操作
    save 300 10
    save 60 10000
        
    stop-writes-on-bgsave-error yes   #持久化错误是否继续工作
    rdbcompression yes #是否压缩rdb文件
    rdbchecksum yes  #是否进行校验
    dir /www/server/redis/   #rdb文件保存目录
    
  • 主从复制

    ################################# REPLICATION #################################
    
    # Master-Replica replication. Use replicaof to make a Redis instance a copy of
    # another Redis server. A few things to understand ASAP about Redis replication.
    
  • Security模块中进行密码设置

    ################################## SECURITY ###################################
    # Require clients to issue AUTH <PASSWORD> before processing any other
    # commands.  This might be useful in environments in which you do not trust
    # others with access to the host running redis-server.
    #
    # This should stay commented out for backward compatibility and because most
    # people do not need auth (e.g. they run their own servers).
    #
    # Warning: since Redis is pretty fast an outside user can try up to
    # 150k passwords per second against a good box. This means that you should
    # use a very strong password otherwise it will be very easy to break.
    #
    # requirepass foobared   //设置密码
    
  • 客户端

    ################################### CLIENTS ####################################
    # maxclients 10000   #最大客户端的数量
    ############################## MEMORY MANAGEMENT ################################
    # maxmemory <bytes>   #最大内存限制
    # maxmemory-policy noeviction   # 内存达到限制值的处理策略
    

    redis 中的默认的过期策略是 volatile-lru

    • maxmemory-policy 六种方式
      **1、volatile-lru:**只对设置了过期时间的key进行LRU(默认值)

      2、allkeys-lru : 删除lru算法的key

      **3、volatile-random:**随机删除即将过期key

      **4、allkeys-random:**随机删除

      5、volatile-ttl : 删除即将过期的

      6、noeviction : 永不过期,返回错误

  • AOF配置

    ############################## APPEND ONLY MODE ###############################
    appendonly no   #默认不开启AOF
    appendfilename "appendonly.aof"   #持久化文件名字
    
    # appendfsync always   #每一次修改都会同步
    appendfsync everysec   #每一秒执行一次
    # appendfsync no  # 不同步
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值