redis配置文件详解

redis值钱操作

1、redis.config详解

单位
# Redis configuration file example

# 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.  
															`对大小写不敏感`
  • 1、配置文件Unit单位对大小写不敏感
包含 INCLUDES
################################## 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.
#
# Notice 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 c:\path\to\other.conf
网络配置
bind 127.0.0.1   		  #绑定的IP
protected-mode yes    #保护模式
port 6379             #端口
通用 GENERAL
daemonize yes  #以守护进程的方式运行,默认是no,我们需要自己配置开启为yes

#日志
# 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


#生成的日志文件地址
# Specify the log file name. Also 'stdout' can be used to force
# Redis to log on the standard output.
logfile ""   #日志的文件位置名

databases 16   #数据库的数量

syslog-enabled yes   #是否总是显示LOGO
快照 SNAPSHOTTING
  • 持久化,在规定时间内,执行了多少次操作,则会持久化到文件。 .rdb .aof

  • redis 是内存数据库,如果没有持久化那么数据断电即失!

# 如果900s内,至少有一个 key进行了修改,我们及时进行持久化操作。
save 900 1
# 如果300s内,至少有10个 key进行了修改,我们及时进行持久化操作。
save 300 10
# 如果60s内,至少有10000个 key进行了修改,我们及时进行持久化操作。
save 60 10000

#我们之后学习持久化,会设置自己的

stop-writes-on-bgsave-error yes  #持久化出错了是否继续工作

rdbcompression yes   #是否压缩rdb文件,需要消耗一些CPU资源。

rdbchecksum yes  #保持rdb文件的时候,进行错误检查校验。

dir ./   #rdb文件保存的目录。
REPLICATION 复制,后面会有讲解。
安全 SECURITY
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379>
# 密码默认是空的

################################## 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

# 可以手动的设置密码。
requirepass 123456

# 可以在终端设置密码
127.0.0.1:6379> config get requirepass # 获取密码
1) "requirepass"
2) ""
127.0.0.1:6379> config set requirepass 123456  # 设置密码
OK
127.0.0.1:6379> config get requirepass  # 这个时候发现命令不能使用了。
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456             # 用密码登录就可以了
OK
127.0.0.1:6379> config get requirepass   # 查询设置后的密码
1) "requirepass"
2) "123456"
127.0.0.1:6379>
限制 LIMITS
# maxclients 10000  # 设置能链接上redis的最大客户端数量

# maxmemory <bytes>  # redis 配置最大的内存容量

# maxmemory-policy noeviction  #内存到达上限后的处理策略。

                    # maxmemory-policy 六种方式
                    1、volatile-lru:只对设置了过期时间的key进行LRU(默认值) 
                    2、allkeys-lru : 删除lru算法的key   
                    3、volatile-random:随机删除即将过期key   
                    4、allkeys-random:随机删除   
                    5、volatile-ttl : 删除即将过期的   
                    6、noeviction : 永不过期,返回错误
APPEND ONLY MODE aof配置
appendonly no  #默认不开启aof模式的,使用后的是rdb方式进行持久化的,因为rdb完全够用了。

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、付费专栏及课程。

余额充值