redis 的使用 及 配置文件解读
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 set aaa
OK
-a指定密码(会有警告密码暴露外边,所以一般不用)
redis-cli -a
--raw 显示中文字符
redis-cli --raw
通过客户端操作redis数据库
set id #写入一条数据key(id),value(1)
get id #取值key(id)
del id #删除key(id)
incr id #自增1 id变为2
incrby id 5 #自增指定数值5 id变为7
decr id #自减1 id变为6
decrby id5 #自减指定数值5 id变为1
getset id 6 #设置新数据并显示原数据
mset name zhangsan age 44 #批量写操作 key为name值为zhangsan key为age值为44
mget name age #批量读操作 一次行查看name和age的值
append name feng #追加字符串 结果为zhangsanfeng
exists id #验证key是否存在
keys * #查看redis里所有的key 不建议使用,上千万的key会使redis服务器堵塞
select #切换到表1模式 redis总共有默认16个表
randomkey #随机返回一个key
scan #分页查看key
select 0 #表示切换到0库 默认16个库
#通过help命令来查找命令
#输入help 多次<Tab>键来切换所有命令
help @hash
info #查看各项信息
info cpu #查看CPU信息
info memory #查看内存信息
info clients #查看客户端信息
info replication #查看同步信息
批量往redis server上插入数据
for line in `seq -w `;do redis-cli set name_${line} value_${line};done
给redis增加密码的两种方式
vim /usr/local/redis/conf/redis.conf #修改配置文件设置密码
requirepass "" #设置密码
#交互式登陆redis设置密码
redis-cli config get requirepass #获取redis配置的密码信息
) "requirepass"
) "" #此时密码空 config set requirepass #给redis设置密码密码即时生效
OK auth #进行密码验证 config get requirepass #查看密码配置信息
) "requirepass"
) "" #有密码了
config rewrite #将配置重写进行保存
OK #查看redis配置文件最后两行
tail - /usr/local/redis/conf/redis.conf
# Generated by CONFIG REWRITE
requirepass "yunjisuan" #增加了密码配置
解读配置文件
基本设置
#redis支持include功能
include /path/to/local.conf
include /path/to/other.conf #redis是否后台运行
daemonize no #pid号保存文件的位置
pidfile /var/run/redis.pid #redis默认监听端口
port #调整tcp监听队列
tcp-backlog #调整redis的监听地址
bind 192.168.1.100 10.0.0.1
bind 127.0.0.1 #调整客户端超时时间
timeout #调整tcp的会话保持时间
tcp-keepalive #调整日志级别
loglevel notice #是否启用syslog来接收日志(比如日志集中收集)
syslog-facility local0 #设置数据库的数量,如果缺省,默认为0(select0...select 15)
databases #如果bgsave出错是否停止写入
stop-writes-on-bgsave-error yes #redis将数据存储在磁盘的什么位置
dbfilename dump.rdb #指定redis配置文件当前工作的路径(指定dbfilename的当前路径位置)
dir ./ #给redis设定密码
requirepass #修改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 -> don't 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 sec ( min) if at least key changed
# after sec ( min) if at least keys changed
# after sec if at least 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秒内至少1key数据变化,但会阻塞用户请求,高并发时不用
save #300秒内至少10key数据变化,但会阻塞用户请求,高并发时不用
save #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 的使用 及 配置文件解读的更多相关文章
- redis cluster的conf配置文件配置
redis cluster的conf配置文件配置 master配置文件如下: bind 127.0.0.1 port tcp-backlog timeout tcp-keepalive logleve ...
- 【比赛打分展示双屏管理系统-专业版】Other.ini 配置文件解读以及排行榜界面及专家评语提交展示等具体配置
第一个问题:Other.ini配置文件的解读: 在软件根目录下,找到Other.ini配置文件,打开如下: 配置文件解读: iOrderIDOrXSID:默认为0,按照软件 选项/排行榜和奖项 的设置 ...
- redis启动时指定配置文件
Redis 启动时指定配置文件需要通过 redis 服务启动才行: 安装服务的教程:http://blog.csdn.net/justinytsoft/article/details/54580919 ...
- Nginx 小入门记录 之 Nginx 配置文件解读(二)
上一小节主要是记录一些环境准备和Nginx的安装,接下来对Nginx基本配置进行记录. 查看配置文件安装记录 可以通过以下Linux命令进行查看: rpm -ql nginx rpm 是liunx的包 ...
- 从零开始Pytorch-YOLOv3【笔记】(一)配置文件解读
前言 这是github上的一个项目YOLO_v3_tutorial_from_scratch,它还有相应的blog对其详细的解读.机器之心翻译了他的tutorial:从零开始PyTorch项目:YOL ...
- Redis配置文件解读
转载自:http://www.cnblogs.com/daizhj/articles/1956681.html 对部分配置选项做了一些说明 把配置项目从上到下看了一遍,有了个大致的了解,暂时还用不到一 ...
- redis 配置文件解读
# Redis 配置文件 # 当配置中需要配置内存大小时,可以使用 1k, 5GB, 4M 等类似的格式,其转换方式如下(不区分大小写) # # 1k => 1000 bytes # 1kb = ...
- redis 哨兵配置文件解读sentinel.conf
# Example sentinel.conf # port <sentinel-port>port 8001 # 守护进程模式daemonize yes # 指明日志文件名logfile ...
- StackExchange.Redis.Extensions.Core 源码解读之 Configuration用法
前言 之前接触到Redis,然后选用了对StackExchange.Redis又一层封装的StackExchange.Redis.Extensions.Core类库.阅读源代码的过程中发现了他使用Co ...
随机推荐
- SAP成都研究院李三郎:SCP Application Router简介
今天的文章来自李贝宁(Ben),SAP成都研究院的资深程序猿和架构师. 作为成都研究院里同时精通Java, JavaScript和ABAP这三门编程语言的数位同事之一,Ben曾经先后担任了成都CRM ...
- sklearn--回归
一.线性回归 LinearRegression类就是我们平时所说的普通线性回归,它的损失函数如下所示: 对于这个损失函数,一般有梯度下降法和最小二乘法两种极小化损失函数的优化方法,而scikit-le ...
- winform 导入 导出 excel
https://blog.csdn.net/pp_fzp/article/details/51502233
- Vue介绍:vue导读1
一.什么是vue 二.如何在页面中使用vue 三.vue的挂载点 四.vue的基础指令 一.什么是vue 1.什么是vue vue.js十一个渐进式javascript框架 渐进式:vue从控制页面中 ...
- PAT Basic 1063 计算谱半径 (20 分)
在数学中,矩阵的“谱半径”是指其特征值的模集合的上确界.换言之,对于给定的 n 个复数空间的特征值 { , },它们的模为实部与虚部的平方和的开方,而“谱半径”就是最大模. 现在给定一些复数空间的特征 ...
- P3528 [POI2011]PAT-Sticks
题目概述 题目描述 给出若干木棍,每根木棍有特定的颜色和长度.问能否找到三条颜色不同的木棍构成一个三角形. (注意这里所说的三角形面积要严格大于\(0\)) 输入格式 第一行给出一个整数\(k\),表 ...
- php 5.6 与 php 7 的区别
1. PHP7.0 比PHP5.6性能提升了两倍. 2.PHP7.0全面一致支持64位. 3.PHP7.0之前出现的致命错误,都改成了抛出异常. 4.增加了空结合操作符(??).效果相当于三元运算符. ...
- visual studio 和visual studio code 的区别是什么?
区别有三: 区别一:含义不一样. Visual Studio(简称VS)是美国微软公司的开发工具包系列产品,是一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具.代码 ...
- Kubernetes1.16下部署Prometheus+node-exporter+Grafana+AlertManager 监控系统
Prometheus 持久化安装 我们prometheus采用nfs挂载方式来存储数据,同时使用configMap管理配置文件.并且我们将所有的prometheus存储在kube-system #建议 ...
- debug:The key "" is not recognized and ignored.
今天写代码时候发现chrome浏览器有一个警告The key "" is not recognized and ignored.既然发现了就处理一下吧,于是就有了这篇小文章. 查阅 ...