redis

Redis
简介
用于:存储计数器数据
KV 存储
可以持久化存储
nosql不同流派的的解决方案其中之一
nosql 特性:数据量大、数据变化非常快(数据增长快、流量分布变化大、数据间耦合结构变化快)、数据源很多;
http://www.nosql-databases.org/
nosql的统计站点
schema-free:行的字段可以不一致
easy replication support :简单的复制
simple API, eventually consistent / BASE (not ACID),
huge amount of data:海量数据
大方向分类:
Wide Column Store / Column Families
列式存储
代表:
Hadoop / HBase
Cassandra
Hypertable
Document Store
文档存储
代表:
MongoDB
Elastic
Key Value / Tuple Store
键值/元组存储
代表:
DynamoDB
Redis:also lists, sets, sorted sets, hashes, queues. Cheat-Sheet:
Graph Databases
图式存储
代表:
Neo4J
TITAN
Multimodel Databases
没有特点的数据库
代表:
ArangoDB
Object Databases
对象存储
Time Series / Streaming Databases
时间序列存储,流式数据
代表:
influxdata
基本架构
client
前端接入
调度
HTTP 协议接入,游戏自己开发协议,
反正都需要协议
动态资源
缓存层
半结构化数据
非结构化数据
图片数据
中间层
转接器,如Nginx,基于模块适于其他协议。
如果需要,建立集群。
分布式存储系统
对象存储系统
静态内容
web
其他数据
搜索引擎

                            计数器

redis
结构化数据
数据库读写分离器
关系型数据库
集群
MHA组件
一脸懵逼
数据的表现可以抽象为各种表示形式 ,如mysql的表结构
分布式存储
存在中心节点
中心节点负责存储元数据,如名称,块分布信息等
其他节点负责存储数据
结构
Client
中心节点
节点
节点
节点
进行分片,并记录分片信息
旁挂式
需要客户端支持该种操作方式

        无中心节点
            结构
                client
                    注册系统
                        注册系统
                            注册系统
                                ETCD

协议:raft
解决方案
chubby
zookeeper
协议 :zab
解决方案
冗余

                        节点
                        节点
                        节点
        冗余
            节点级冗余
                即冗余整个节点数据
            数据块冗余
                冗余整个数据块
            数据完整性通过客户端校验码校验 
        任何分布系统都仅能实现3种特性中的两种 
            P :分区容错 

网络发生分区后,服务是否依然可用
集群发生分区后可以正常工作
A :可用性
用户发出请求后的有限时间范围内返回结果;
C :一致性
多个数据节点上的数据一致;
组合可能性
AP
AC
CP:这个好尴尬
折中
AP为主 ,弱一致性
某段时间内,数据可以不一致。
结果一致性
分布式系统应遵循
BASE法则
事务型存储引擎应满足ACID测试
BA
基本可用
S
在一定时间内不一致
E
最终一致
CAP 与BASE 理论支撑了现代分布式系统的构建
分布式系统分为,分布式存储,分布式运算
分布式存储
文件接口进行抽象,NoSQL,即数据库
分布式文件系统,对文件接口做了弱化,
NewSql
Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.
开源、内存存储、数据结构存储;
可用作:数据库、缓存、消息队列;
支持的数据结构:
It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries.
数据结构:字符串、列表(数组)、hashes(关联数组)、集合、有序集合、bitmaps、hyperloglogs、空间索引;
支持的功能:
Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
内建的复制、Lua scripting、LRU、事务、持久存储、高可用(Sentinel,Redis Cluster)
工作特性
REmote DIctionary Server:数据结构服务器,k/v,数据结构;
内存存储:in-memroy
持久化
主从(sentinel)
Cluster(shard)
数据结构服务器:
Strings, Lists, Hashs, Sets, Sorted Sets, Bitmaps, Hyperloglogs
PUB/SUB
单进程:
CPU并非瓶颈;
持久化:
snapshotting :快照
AOF :追加文件
Replication:
主/从
主:rw
从:read-only
使用 tcp 的 6379 端口
存储的数据结构都为键值类型,
但是值可以有多种类型
字符串、列表(数组)、hashes(关联数组)、集合、有序集合、bitmaps、hyperloglogs、空间索引
安装
yum安装
配置epel 仓库,并安装
yum -y install epel-release
rem -ql epel-release
rpm -ql epel-release
yum info redis
yum -y install redis
/usr/lib/systemd/system/redis-sentinel.service
启动文件
/usr/lib/systemd/system/redis-sentinel.service
哨兵服务的启动文件
/usr/libexec/redis-shutdown
关闭redis的程序
/usr/bin/redis-server
主程序
/usr/bin/redis-cli
客户端程序
/usr/bin/redis-sentinel
类似于MHA的解决方案
/usr/bin/redis-check-aof
/usr/bin/redis-check-rdb
检测工具
/usr/bin/redis-benchmark
评估redis性能
/etc/redis.conf
主配置文件
/etc/redis-sentinel.conf
sentinel的配置文件
/var/lib/redis
数据存放目录
/var/log/redis
日志文件
/var/run/redis
配置
配置文件
/etc/redis.conf
INCLUDES
包含其他的配置文件
# include /path/to/local.conf

include /path/to/other.conf

包含其他的配置文件
NETWORK
网络配置相关的字段
bind
监听的地址
在不指定的情况下 监听0.0.0.0地址
protected-mode yes
是否工作于保护模式
port
指定监听的端口
tcp-backlog 511
队列长度
unixsocket /tmp/redis.sock
监听的sock文件
timeout 0
redis连接的无操作超时时长
tcp-keepalive 300
tcp保持连接的时长
保护模式开启,
bind 与 密码认证都没有显式的指定, 保护模式生效,即只监听 本地环回地址
GENERAL
通用配置
daemonize是否以守护进程运行
supervised
# If you run Redis from upstart or systemd, Redis can interact with your

supervision tree. Options:

supervised no - no supervision interaction

supervised upstart - signal upstart by putting Redis into SIGSTOP mode

supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET

supervised auto - detect upstart or systemd method based on

UPSTART_JOB or NOTIFY_SOCKET environment variables

Note: these supervision methods only signal “process is ready.”

They do not enable continuous liveness pings back to your supervisor.

supervised no
鬼知道什么意思,马哥不好好讲
loglevel指定日志级别
pidfilepid文件的位置
logfile 日志文件的位置
databases:设定数据库数量,默认为16个,每个数据库的名字均为整数,从0开始编号,默认操作的数据库为0;
SNAPSHOTTING
快照持久机制,相关配置,类似于备份的实现
REPLICATION
主从同步复制,相关吧配置
SECURITY
安全相关
requirepass <密码>
设定登录密码
rename-command 对命进行重命名
rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 对CONFIG(全局参数设置指令)进行重命名
在AOF或Replication环境中,不推荐使用
LIMITS
系统资源使用限制
maxclients 最大并发连接数
maxmemory 最大内存
maxmemory-policy noeviction 内存,淘汰策略:
volatile-lru 将存在过期时间的键,进行lru算法进行淘汰
allkeys-lru 将所有的键都使用lry进行淘汰
volatile-random 将存在过期时间的键 进行随机淘汰
allkeys-random 所有键随机淘汰
volatile-ttl 将设定了过期时间的键,按照剩余的存在时间进行淘汰.
noeviction 不启用内存淘汰策略,当内存占满后会报错.
maxmemory-samples 5 淘汰算法运行时的采样样本数;即每次提取5个键,在5个键中进行淘汰.
APPEND ONLY MODE
持久化机制2,的相关配置,类似于二进制日志文件的实现
LUA SCRIPTING
REDIS CLUSTER
redis 集群相关
SLOW LOG
慢查询日志
slowlog-log-slower-than 10000 设置查询为慢查询的时间,单位是微秒;
slowlog-max-len 128 每行日志,的最大长度,单位字节.
SlowLog记录的日志最大条目;
LATENCY MONITOR
延迟监控
latency-monitor-threshold 0
何时启用延迟监视器,0为一致开启
EVENT NOTIFICATION
事件通知
ADVANCED CONFIG
高级配置
hash-max-ziplist-entries 512 关联数组最多允许出现的项目数
hash-max-ziplist-value 64 每个成员的值的长度.
设置ziplist的键数量最大值,每个值的最大空间; 格式为: 关键字 客户端类型 硬限制 软限制 硬限制的过期时长 ,
即以软限制为基本限制,可以临时超出到硬限制的上限,但是仅能超出硬限制的设定时间.
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
命令行使用
redis-cli
连接数据库
格式:
redis-cli [ options ] [cmd [arg [arg …]]]
[ options ]
-h hostname Server hostname (default: 127.0.0.1).
-p port Server port (default: 6379).
-s socket Server socket (overrides hostname and port).
-a password Password to use when connecting to the server. 只有认证,不需要用户名
help
帮助
To get help about Redis commands type:
“help @” to get a list of commands in
“help ” for help on
“help ” to get a list of possible help topics
“quit” to exit

To set redis-cli perferences:
“:set hints” enable online hints
“:set nohints” disable online hints
Set your preferences in ~/.redisclirc
命令分组 @<>表示一个组
<> 表示单个的命令
tab 补全
SELECT
切换数据库,在不指定数据库编号时,默认为0数据库,默认数据库存在16个(0-15)
字符串相关
help @string
SET key value [EX seconds:过期时间] [PX milliseconds] [NX:不存在时创建|XX]
Set the string value of a key
将指定的KEY的值设置为 指定的value
MSET key value [key value …]
summary: Set multiple keys to multiple values
一次设定多个键值
SETNX key value
summary: Set the value of a key, only if the key does not exist
设置一个键的值,当这个键不存在时.
GET key
summary: Get the value of a key
获取对应的Key 的值
MGET key [key …]
summary: Get the values of all the given keys
一次获取多个键的值
APPEND key value
summary: Append a value to a key
在指定的Key后追加value
DECR key
summary: Decrement the integer value of a key by one
指定的键 自减 1
DECRBY key decrement
summary: Decrement the integer value of a key by the given number
指定的键减去一个固定的值
INCR key
summary: Increment the integer value of a key by one
指定的键自增1
INCRBY key increment
summary: Increment the integer value of a key by the given amount
指定的键减去一个固定的值
STRLEN key
summary: Get the length of the value stored in a key
获取指定键的值的长度
SETEX key seconds value
summary: Set the value and expiration of a key
其他命令
BITCOUNT key [start end]
summary: Count set bits in a string
since: 2.6.0
BITFIELD key [GET type offset] [SET type offset value] [INCRBY type offset increment] [OVERFLOW WRAP|SAT|FAIL]
summary: Perform arbitrary bitfield integer operations on strings
since: 3.2.0
BITOP operation destkey key [key …]
summary: Perform bitwise operations between strings
since: 2.6.0
BITPOS key bit [start] [end]
summary: Find first bit set or clear in a string
since: 2.8.7
GETBIT key offset
summary: Returns the bit value at offset in the string value stored at key
since: 2.2.0
GETRANGE key start end
summary: Get a substring of the string stored at a key
since: 2.4.0
GETSET key value
summary: Set the string value of a key and return its old value
since: 1.0.0
INCRBYFLOAT key increment
summary: Increment the float value of a key by the given amount
since: 2.6.0
MSETNX key value [key value …]
summary: Set multiple keys to multiple values, only if none of the keys exist
since: 1.0.1
PSETEX key milliseconds value
summary: Set the value and expiration in milliseconds of a key
since: 2.6.0
SETBIT key offset value
summary: Sets or clears the bit at offset in the string value stored at key
since: 2.2.0
SETRANGE key offset value
summary: Overwrite part of a string at key starting at the specified offset
since: 2.2.0
也可以设置为数值,字符串包含数值
列表相关
help @list
列队结构,数值可以从左右两侧进入,左右两侧弹出
也可在指定位置插入值
索引排序:
0 1 2 3 4 5 6 7 8 9
先进先出:队列
先进后出:栈
LSET key index value
summary: Set the value of an element in a list by its index
根据索引设定列表中元素的值
RPUSH key value [value …]
summary: Append one or multiple values to a list
从右侧增加一个元素
LPUSH key value [value …]
summary: Prepend one or multiple values to a list
从左侧增加一个元素
RPOP key
summary: Remove and get the last element in a list
从右侧弹出指定队列的一个元素
LPOP key
summary: Remove and get the first element in a list
从左侧弹出指定队列的一个元素
LINDEX key index
summary: Get an element from a list by its index
获取指定索引的值
LINSERT key BEFORE|AFTER pivot value
summary: Insert an element before or after another element in a list
向指定的索引插入指定的值
LLEN key
summary: Get the length of a list
获取列表中的元素个数
RPUSHX key value
summary: Append a value to a list, only if the list exists
仅当列表存在时,才向其中追加元素,为右增
LPUSHX key value
summary: Prepend a value to a list, only if the list exists
仅当列表存在时,才向其中追加元素,为左增
LREM key count value
summary: Remove elements from a list
删除指定列表中的指定值
其它选项
BLPOP key [key …] timeout
summary: Remove and get the first element in a list, or block until one is available
since: 2.0.0
BRPOP key [key …] timeout
summary: Remove and get the last element in a list, or block until one is available
since: 2.0.0
BRPOPLPUSH source destination timeout
summary: Pop a value from a list, push it to another list and return it; or block until one is available
since: 2.2.0
LRANGE key start stop
summary: Get a range of elements from a list
since: 1.0.0
LTRIM key start stop
summary: Trim a list to the specified range
since: 1.0.0
RPOPLPUSH source destination
summary: Remove the last element in a list, prepend it to another list and return it
since: 1.2.0
字典,映射
help @hash
HSET key field value
summary: Set the string value of a hash field
设定指定字典的索引下标与下标对应的值
HMSET key field value [field value …]
summary: Set multiple hash fields to multiple values
设定指定字典的索引下标与下标对应的值,可以连续设定多个
HGET key field
summary: Get the value of a hash field
获取指定字典中指定的下标的值
HMGET key field [field …]
summary: Get the values of all the given hash fields
获取多个指定字典中指定下标的值
HLEN key
summary: Get the number of fields in a hash
获取指定字典中的元素个数
HKEYS key
summary: Get all the fields in a hash
显示指定字典中的所有元素的下标
HVALS key
summary: Get all the values in a hash
显示指定字典中所有的值
HEXISTS key field
summary: Determine if a hash field exists
判断指定的字典是否存在指定的下标
HDEL key field [field …]
summary: Delete one or more hash fields
删除指定字典中的指定下标
其他命令
HGETALL key
summary: Get all the fields and values in a hash
since: 2.0.0
HINCRBY key field increment
summary: Increment the integer value of a hash field by the given number
since: 2.0.0
HINCRBYFLOAT key field increment
summary: Increment the float value of a hash field by the given amount
since: 2.6.0
HSCAN key cursor [MATCH pattern] [COUNT count]
summary: Incrementally iterate hash fields and associated values
since: 2.8.0
HSETNX key field value
summary: Set the value of a hash field, only if the field does not exist
since: 2.0.0
HSTRLEN key field
summary: Get the length of the value of a hash field
since: 3.2.0
即关联数组
集合.无序
help @set
交集,并集,补集
SADD key member [member …]
summary: Add one or more members to a set
定义一个集合
SINTER key [key …]
summary: Intersect multiple sets
取两个集合的交集
SINTERSTORE destination key [key …]
summary: Intersect multiple sets and store the resulting set in a key
取两个元素的交集 并将保存的元素的保存为一个新的集合
SUNION key [key …]
summary: Add multiple sets
取两个集合的并集,即两个集合的全部,不算重复的
SUNIONSTORE destination:新的集合的名称 key [key …]
summary: Add multiple sets and store the resulting set in a key
取两个元素的并集 并将保存的元素的保存为一个新的集合
SDIFF key [key …]
summary: Subtract multiple sets
取两个集合的差集, key1 有而key2 没有的
SDIFFSTORE destination key [key …]
summary: Subtract multiple sets and store the resulting set in a key
取两个元素的差集, 并将保存的元素的保存为一个新的集合
SREM key member [member …]
summary: Remove one or more members from a set
从指定的集合中移除指定的元素
SPOP key [count]
summary: Remove and return one or multiple random members from a set
随机的弹出一个元素
SMEMBERS key
summary: Get all the members in a set
获取一个集合的所有元素
其他选项
SCARD key
summary: Get the number of members in a set
since: 1.0.0
SISMEMBER key member
summary: Determine if a given value is a member of a set
since: 1.0.0
SMOVE source destination member
summary: Move a member from one set to another
since: 1.0.0
SRANDMEMBER key [count]
summary: Get one or multiple random members from a set
since: 1.0.0
SSCAN key cursor [MATCH pattern] [COUNT count]
summary: Incrementally iterate Set elements
since: 2.8.0
有序集合
help @sorted_set
ZADD key [NX|XX] [CH] [INCR] score:值数字 member:用于排序的下标字符串 [score member …]
summary: Add one or more members to a sorted set, or update its score if it already exists
添加一个有序的集合
ZCARD key
summary: Get the number of members in a sorted set
列出集合中的所有的键的members
ZCOUNT key min max
summary: Count the members in a sorted set with scores within the given values
统计指定值范围内的元素数量
ZRANGE key start stop [WITHSCORES]
summary: Return a range of members in a sorted set, by index
基于索引显示即显示指定索引范围内的成员
ZSCORE key member
summary: Get the score associated with the given member in a sorted set
获取指定成员的 值
ZREMRANGEBYRANK key start stop
summary: Remove all members in a sorted set within the given indexes
删除指定索引范围内的成员
ZREMRANGEBYSCORE key min max
summary: Remove all members in a sorted set within the given scores
删除指定值范围内的成员
ZRANK key member
summary: Determine the index of a member in a sorted set
查看指定集合中指定的元素的对应索引
其他选项
ZINCRBY key increment member
summary: Increment the score of a member in a sorted set
since: 1.2.0
ZINTERSTORE destination numkeys key [key …] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
summary: Intersect multiple sorted sets and store the resulting sorted set in a new key
since: 2.0.0
ZLEXCOUNT key min max
summary: Count the number of members in a sorted set between a given lexicographical range
since: 2.8.9
ZRANGEBYLEX key min max [LIMIT offset count]
summary: Return a range of members in a sorted set, by lexicographical range
since: 2.8.9
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
summary: Return a range of members in a sorted set, by score
since: 1.0.5
ZREM key member [member …]
summary: Remove one or more members from a sorted set
since: 1.2.0
ZREMRANGEBYLEX key min max
summary: Remove all members in a sorted set between the given lexicographical range
since: 2.8.9
ZREMRANGEBYSCORE key min max
summary: Remove all members in a sorted set within the given scores
since: 1.2.0
ZREVRANGE key start stop [WITHSCORES]
summary: Return a range of members in a sorted set, by index, with scores ordered from high to low
since: 1.2.0
ZREVRANGEBYLEX key max min [LIMIT offset count]
summary: Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.
since: 2.8.9
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
summary: Return a range of members in a sorted set, by score, with scores ordered from high to low
since: 2.2.0
ZREVRANK key member
summary: Determine the index of a member in a sorted set, with scores ordered from high to low
since: 2.0.0
ZSCAN key cursor [MATCH pattern] [COUNT count]
summary: Incrementally iterate sorted sets elements and associated scores
since: 2.8.0
ZUNIONSTORE destination numkeys key [key …] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
summary: Add multiple sorted sets and store the resulting sorted set in a new key
since: 2.0.0
发布订阅
help @pubsub
PSUBSCRIBE pattern [pattern …]
summary: Listen for messages published to channels matching the given patterns
订阅频道,可以连续订阅多个频道
PUBLISH channel message
summary: Post a message to a channel
向一个频道中发送信息
PUBSUB subcommand [argument [argument …]]
summary: Inspect the state of the Pub/Sub subsystem
查看频道的信息
PUNSUBSCRIBE [pattern [pattern …]]
summary: Stop listening for messages posted to channels matching the given patterns
取消订阅
SUBSCRIBE channel [channel …]
summary: Listen for messages published to the given channels
订阅,可以订阅多个频道
UNSUBSCRIBE [channel [channel …]]
summary: Stop listening for messages posted to the given channels
取消订阅
用于消息推送,
事务
help @transactions
DISCARD -
summary: Discard all commands issued after MULTI

          EXEC -
          summary: Execute all commands issued after MULTI
          since: 1.2.0

          MULTI -
          summary: Mark the start of a transaction block
          启动一个多语句事务

          UNWATCH -
          summary: Forget about all watched keys


          WATCH key [key ...]
          summary: Watch the given keys to determine execution of the MULTI/EXEC block
          触发器.key的值发生变化,触发语句
    连接

help @connection
AUTH password
summary: Authenticate to the server
认证

          ECHO message
          summary: Echo the given string
          since: 1.0.0

          PING [message]
          summary: Ping the server
          探测服务器是否在线

          QUIT -
          summary: Close the connection
          since: 1.0.0

          SELECT index
          summary: Change the selected database for the current connection
          切换数据库
    服务器相关命令

help @server
INFO [section]
INFO [server| client]
summary: Get information and statistics about the server
显示服务器信息,硬件,平台,架构,运行信息.
FLUSHDB -
summary: Remove all keys from the current database
清空指定数据库
FLUSHALL -
summary: Remove all keys from all databases
清空所有数据库
CLIENT LIST -
summary: Get the list of client connections
列出所有的终端
CLIENT SETNAME connection-name
summary: Set the current connection name
为客户端指定名称
运行参数相关
运行参数可以运行时修改
CONFIG GET 获取参数值
CONFIG RESETSTAT 重置,各种计数器.
CONFIG REWRITE 将内存中的设定覆盖值文件中
CONFIG SET 设定参数
例:CONFIG SET requirepass jinbus
注意:严重区分大小写
持久化
Redis的持久化:对数据保存的补充,为了宕机后的数据恢复.
RDB:snapshotting, 二进制格式;按事先定制的策略,周期性地将数据从内存同步至磁盘;数据文件默认为dump.rdb;
主机宕机后可能会丢失一部分数据.即快照备份后生成的新数据
客户端显式使用SAVE或BGSAVE命令来手动启动快照保存机制;
SAVE:同步,即在主线程中保存快照,此时会阻塞所有客户端请求;
BGSAVE:异步,即开启子进程,子进程负责进行数据同步.
RDB相关的配置:
*save

save 900 1
save 300 10
save 60 10000

表示:三个策略满足其中任意一个均会触发SNAPSHOTTING操作;900s内至少有一个key有变化,300s内至少有10个key有变化,60s内至少有1W个key发生变化;
        stop-writes-on-bgsave-error yes dump操作出现错误时,即建立快照时发生错误,是否禁止新的写入操作请求;

        rdbcompression yes 快照文件是否压缩
        rdbchecksum yes 是否对RDB文件进行校验
        dbfilename dump.rdb:指定rdb文件的名称
        *dir /var/lib/redis:指定rdb文件的保存路径,同时也决定了AOF的路径
    AOF:Append Only File, fsync
记录每次写操作至指定的文件尾部实现的持久化;当redis重启时,可通过重新执行文件中的命令在内存中重建出数据库;
    BGREWRITEAOF:AOF文件重写;
        不会读取正在使用AOF文件,而是通过将内存中的数据以命令的方式保存至临时文件中,完成之后替换原来的AOF文件;
        *appendonly no   是否开启AOF功能
        appendfilename "appendonly.aof" 保存的aof文件的名称
        *appendfsync  即进行aof持久化的策略,即将aof记录至内存后与硬盘的同步的时刻.可以有多种模式
    no:redis不执行主动同步操作,而是OS进行;即内核决定将内存写入磁盘.
    everysec:每秒一次,即每秒与硬盘同步一次.
    always:每语句一次,即每在内存中改动数据后,立即将语句记录到硬盘上.
        no-appendfsync-on-rewrite no 是否在后台执行aof重写期间不调用fsync(内存同步至硬盘),默认为no,表示调用;如果不调用时,重写时服务器崩溃了,那么会丢失内存中没有同步的数据.
        重写触发条件  

auto-aof-rewrite-percentage 100 变化的数据量超过原有数据的100%
auto-aof-rewrite-min-size 64mb 文件大小达到64M
上述两个条件同时满足时,方会触发重写AOF;与上次aof文件大小相比,其增长量超过100%,且大小不少于64MB;
aof-load-truncated yes redis崩溃后,再次重启后,aof重放完成,后是否删除 aof文件.然后进行重写.
RDB与AOF同时启用:
(1) BGSAVE和BGREWRITEAOF不会同时进行;
(2) Redis服务器启动时用持久化的数据文件恢复数据,会优先使用AOF;
主从复制

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值