【Redis】redis.conf 文件详解

一、unit 单位

units are case insensitive so 1GB 1Gb 1gB are all the same表明unit的单位是不分大小写的。

# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 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.

二、合并.conf文件

Include one or more other config files here表明我们可以通过命令将多个.conf文件进行合并,格式:include /path/to/other.conf

################################## INCLUDES ###################################

# Include one or more other config files here.  This is useful if you
# have a standard template that goes to all Redis servers but also need
# to customize a few per-server settings.  Include files can include
# other files, so use this wisely.
#
# Note that option "include" won't be rewritten by command "CONFIG REWRITE"
# from admin or Redis Sentinel. Since Redis always uses the last processed
# line as value of a configuration directive, you'd better put includes
# at the beginning of this file to avoid overwriting config change at runtime.
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
#
# include /path/to/local.conf
# include /path/to/other.conf

三、loadmodule 加载模块

通过这里的 loadmodule 配置将引入自定义模块来新增一些功能。

################################## MODULES #####################################

# Load modules at startup. If the server is not able to load modules
# it will abort. It is possible to use multiple loadmodule directives.
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so

四、NETWORK 网络设置

  46 ################################## NETWORK #####################################
  .......
  72 # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
  73 # JUST COMMENT OUT THE FOLLOWING LINE.
  74 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # 默认只能本机访问,如果是远程调用或者虚拟机调用,需要将其注释掉
  75 bind 127.0.0.1 -::1 
  ......
  90 # By default protected mode is enabled. You should disable it only if
  91 # you are sure you want clients from other hosts to connect to Redis
  92 # even if no authentication is configured, nor a specific set of interfaces
  93 # are explicitly listed using the "bind" directive.
  # 如果你想要通过其他主机连接redis,那么你需要将protected-mode设为no
  94 protected-mode yes
  
  96 # Accept connections on the specified port, default is 6379 (IANA #815344).
  97 # If port 0 is specified Redis will not listen on a TCP socket.
  # 6379是redis的默认端口号,你可以在这里修改redis的端口号
  98 port 6379
  ......
  118 # Close the connection after a client is idle for N seconds (0 to disable)
  # 超时设置
  119 timeout 0



五、GENERAL 一般设置

 252 ################################# GENERAL #####################################
 ......
 291 # Specify the server verbosity level.
 292 # This can be one of:
 293 # debug (a lot of information, useful for development/testing)
 294 # verbose (many rarely useful info, but not a mess like the debug level)
 295 # notice (moderately verbose, what you want in production probably)
 296 # warning (only very important / critical messages are logged)
 # 日志水平 一般使用默认的 notice 就可以
 297 loglevel notice
 298
 299 # Specify the log file name. Also the empty string can be used to force
 300 # Redis to log on the standard output. Note that if you use standard
 301 # output for logging but daemonize, logs will be sent to /dev/null
 # 日志的名字,一般我们不会使用默认的
 302 logfile ""

 324 # Set the number of databases. The default database is DB 0, you can select
 325 # a different one on a per-connection basis using SELECT  where
 326 # dbid is a number between 0 and 'databases'-1
 # 这里就是redis默认额16个数据库的出处
 327 databases 16


六、SNAPSHOTTING 快照

 360 ################################ SNAPSHOTTING  ################################
 ......

 379 # You can set these explicitly by uncommenting the three following lines.
 380 #
 381 # save 3600 1      # 3600秒钟至少有1个键被改变,那么就会进行保存
 382 # save 300 100		# 300秒钟至少有100键被改变,才会进行保存
 383 # save 60 10000    # 60秒中至少有10000个键被改变,才会进行保存
 
 398 stop-writes-on-bgsave-error yes    # 保存失败,停止写入

 404 rdbcompression yes				    # 对持久化的数据进行压缩 

 413 rdbchecksum yes					# 对持久化的数据进行校验

 441 # An alternative (and sometimes better) way to obtain the same effect is
 442 # to use diskless replication on both master and replicas instances. However
 443 # in the case of replicas, diskless is not always an option.
 444 rdb-del-sync-files no    # 是否开启数据同步(我们在做redis集群的时候,这个是需要开启的)

 453 # Note that you must specify a directory here, not a file name.
 454 dir ./          # 持久化数据所存放的文件目录(默认为当前目录)


七、REPLICATION 主从复制

这个会在主从复制专栏中进行详细的讲解

八、SECURITY 安全

 769 ################################## SECURITY ###################################
 ......
 874 # The ACL Log tracks failed commands and authentication events associated
 875 # with ACLs. The ACL Log is useful to troubleshoot failed commands blocked
 876 # by ACLs. The ACL Log is stored in memory. You can reclaim memory with
 877 # ACL LOG RESET. Define the maximum entry length of the ACL Log below.
 # 锁的最大长度为128位
 878 acllog-max-len 128


九、CLIENTS 客户端设置

 949 ################################### CLIENTS ####################################
 ......
 960 # IMPORTANT: When Redis Cluster is used, the max number of connections is also
 961 # shared with the cluster bus: every node in the cluster will use two
 962 # connections, one incoming and another outgoing. It is important to size the
 963 # limit accordingly in case of very large clusters.
 # 设置客户端的最大连接数
 965 # maxclients 10000


十、 MEMORY MANAGEMENT 内存管理

 967 ############################## MEMORY MANAGEMENT ################################
 ......
 988 # In short... if you have replicas attached it is suggested that you set a lower
 989 # limit for maxmemory so that there is some free RAM on the system for replica
 990 # output buffers (but this is not needed if the policy is 'noeviction').
 # 你可以设置redis的最大内存(redis在未进行持久化之前,数据是存在内存中的,断电即失)
 992 # maxmemory 
 .......
 1012 # Note: with any of the above policies, when there are no suitable keys for
 1013 # eviction, Redis will return an error on write operations that require
 1014 # more memory. These are usually commands that create new keys, add data or
 1015 # modify existing keys. A few examples are: SET, INCR, HSET, LPUSH, SUNIONSTORE,
 1016 # SORT (due to the STORE argument), and EXEC (if the transaction includes any
 1017 # command that requires memory).
 1018 #
 1019 # The default is:
 # 设置key过期的策略
 1021 # maxmemory-policy noeviction

maxmemory-policy 六种策略
①、volatile-lru:只最近最少使用算法,从设置了过期时间的键中选择空转时间最长的键值对清除掉;
②、allkeys-lru : 最近最少使用算法,从所有的键中选择空转时间最长的键值对清除;
③、volatile-random:从设置了过期时间的键中,随机选择键进行清除;
④、allkeys-random:所有的键中,随机选择键进行删除;
⑤、volatile-ttl : 从设置了过期时间的键中选择过期时间最早的键值对清除;
⑥、noeviction : 不做任何的清理工作,在redis的内存超过限制之后,所有的写入操作都会返回错误;但是读操作都能正常的进行;

十一、AOP

AOF :Redis 默认不开启。它的出现是为了弥补RDB的不足(数据的不一致性),所以它采用日志的形式来记录每个写操作,并追加到文件中。Redis 重启的会根据日志文件的内容将写指令从前到后执行一次以完成数据的恢复工作。

后面的专栏中会详细讲解AOP



这篇文章确实有些草率了,哭瞎(ಥ_ಥ) …
【Redis】redis.conf 文件详解_第1张图片

你可能感兴趣的:(redis,数据库)