首页 > 其他 > 详细

redis 的使用 及 配置文件解读

时间:2018-08-20 22:31:08      阅读:210      评论:0      收藏:0      [点我收藏+]

redis-server命令

redis-server /usr/local/redis/conf/redis.conf    #加配置文件绝对路径启动redis服务
redis-server /usr/local/redis/conf/redis.conf &  #如果配置文件daemonize yes后台启动没有开启则在结尾&在后台启动

redis-cli命令

redis-cli           #通过客户端连接本地redis 
redis-cli shutdown     #关闭redis服务

-p指定端口

redis-cli -p 6379 

-h指定要连接的reids服务端的IP

redis-cli -h 192.168.50.167

结尾跟内部命令可在外部执行

redis-cli -h 10.0.0.135 -p 6379 set aaa 111
OK

通过客户端操作redis数据库

set id 001      #写入一条数据key(id),value(001
get id          #取值key(id  
del id          #删除key(id    
exists id       #验证key是否存在
keys *          #查看redis里所有的key
select 1        #切换到表1模式   redis总共有默认16个表
#通过help命令来查找命令
#输入help 多次<Tab>键来切换所有命令
help @hash

解读配置文件

基本设置

#redis支持include功能
include /path/to/local.conf
include /path/to/other.conf

#redis是否后台运行
daemonize no   

#pid号保存文件的位置
pidfile /var/run/redis.pid

#redis默认监听端口
port 6379

#调整tcp监听队列
tcp-backlog 511

#调整redis的监听地址
bind 192.168.1.100 10.0.0.1
bind 127.0.0.1

#调整客户端超时时间
timeout 0

#调整tcp的会话保持时间
tcp-keepalive 0

#调整日志级别
loglevel notice

#是否启用syslog来接收日志(比如日志集中收集)
syslog-facility local0

#设置数据库的数量,如果缺省,默认为0(select0...select 15
databases 16

#如果bgsave出错是否停止写入
stop-writes-on-bgsave-error yes

#redis将数据存储在磁盘的什么位置
dbfilename dump.rdb

#指定redis配置文件当前工作的路径(指定dbfilename的当前路径位置)
dir ./

#给redis设定密码
requirepass 123456

#修改redis操作命令的名称
rename-command CONFIG ""
rename-command set ""
rename=command get wk

#设定redis内存限制(但是内存用完后,redis就会开始删除key)
maxmemory <bytes>

#设定redis内存清理的算法
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> dont expire at all, just return an error on write operation
maxmemory-policy volatile-lru

rdb快照设置  (快照及流模式只能用在从不能用在主 主压力太大)

################################ SNAPSHOTTING  ################################
#
# Save the DB on disk:
#
#   save <seconds> <changes>
#
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
#
#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#
#   Note: you can disable saving at all commenting all the "save" lines.
#
#   It is also possible to remove all the previously configured save
#   points by adding a save directive with a single empty string argument
#   like in the following example:
#
#   save ""      #如果不想保存在磁盘,就如此设置 等于关闭快照

save 900 1      #900秒内至少1key数据变化,但会阻塞用户请求,高并发时不用
save 300 10     #300秒内至少10key数据变化,但会阻塞用户请求,高并发时不用
save 60 10000   #60秒内至少10000key数据变化,但会阻塞用户请求,高并发时不用

AOF流模式设置

############################## 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 http://redis.io/topics/persistence for more information.
#是否启用AOF存储模式
appendonly no
#设定AOF文件的存储位置
appendfilename "appendonly.aof"     #并不用于主从同步,只是redis在启动时,读取此文件用于恢复数据
#设定AOF同步存储的时间周期
appendfsync everysec    #每秒或不用

 

redis 的使用 及 配置文件解读

原文:https://www.cnblogs.com/ywrj/p/9508420.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!