Redis入门到秃头
2020-03-11 00:17:42 0 举报
AI智能生成
Redis入门指南
作者其他创作
大纲/内容
持久化
为什么要持久化?
RDB
原理
根据配置规则自动保存快照
子主题
SAVE
BGSAVE
FLUSHALL
执行复制replication
AOF
原理
BGREWRITEAOF
appendfsync
appendfsync always
appendfsync everysec
appendfsync no
集群
为什么要集群
复制replication
原理
配置方法
配置文件 slaveof ip_address port
redis-server --port 6380 --slaveof ip_address port
在运行时salaveof ip_address port
命令
INFO replication
PSYNC
哨兵sentinel
哨兵的功能
配置sentinel.conf
redis-sentinel sentinel.conf
集群cluster
为什么要集群
配置
port
cluster-enable yes
cluster-config-file nodes.conf
redis-trib.rb
增加节点
CLUSTER MEET ip port
插槽分配
16384个插槽
子主题
数据结构
String
介绍
命令
字符串类型
单一键值
SET key value
GET key
多个键值
MSET key1 value1 key2 value2
MGET key1 key2
STRLEN key
APPEND key value
EXISTS key
DEL key
TYPE key
数值型
整数
INCR key
DECR key
INCRBY key increment
DECRBY key decrement
浮点数
INCRBYFLOAT key increment
DECREMENTFLOAT key decrement
Hash
介绍
命令
单一
HSET key field value
HGET key field
多个
HMSET key field1 value1 field2 value2
HMGT key field1 field2
HGETALL key
HEXISTS key field
数值型
HINCRBY key field increment
HDEL key field1 field2
HKEYS key
HVALS key
HLEN key
list
介绍
命令
LPUSH key value1 value2
RPUSH key value1 value2
LPOP key
RPOP key
LLEN key
LRANGE key start_index end_index
count > 0
正数:从左到右,第一位index为0,包头包尾
负数:从右到左,右边第一位index为-1,包头包尾
LREM
LREM key count value
count < 0
count = 0
LINDEX key index
LSET key index value
LTRIM key start_index end_index
LINSERT key BEFORE|AFTER pivot value
RPOPLPUSH source destination
set
介绍
命令
SADD key member1 menber2
SREM key member1 menber2
SMEMBERS key
SISMEMBER key member
SCARD key
集合运算
SDIFF key1 key2 key3
SINTER key1 key2 key3
SUNION key1 key2 key3
SDIFFSTORE des key1 key2 key3
SINTERSTORE des key1 key2 key3
SUNIONSTORE des key1 key2 key3
SRANDMEMBER key count
无count
有count
SPOP key
Zset
介绍
命令
ZADD key score1 member1 score2 member2
ZSCORE key member
ZRANGE
ZRANGE key start stop
ZRANGE key start stop WITHSCORES
ZRANGEBYSCORE
ZRANGE key min max
ZRANGE key min max WITHSCORES
ZRANGE key min max LIMIT offset count
ZINCRBY key increment member
ZCARD key
ZCOUNT key min max
ZREM key member1 member2
ZREMRANGEBYRANK key start_index end_index
ZREMRANGEBYSCORE key min max
ZRANK key member
ZREVRANK key member
ZINTERSRORE
ZINCRBY key increment member
ZCARD key
ZCOUNT key min max
ZREM key member1 member2 member3
ZREMRANGEBYRANK key start stop
进阶
事务
MULTI
语法错误
运行错误
WATCH
过期
EXPIRE key seconds
PEXPIRE key milis
TTL key
PTTL key
PERSIST key
SET key value
GETSET key value
排序
SORT
可排序类型
list
zset
set
SORT list DESC
SORT list LIMIT offset count
BY
GET
STORE
任务队列
BRPOP queue outtime
BRPOP queue1 queue2 queue3 outtime
BLPOP
发布/订阅
PUBLISH channel message
SUBSCRIBE channel1 channel2 channel3
subscribe
message
unsubscribe
UNSUBSCRIBE channel1 channel2
PSUBSCRIBE channel_pattern_1 channel_pattern_2
PUNSUBSCRIBE channel_pattern_1 channel_pattern_2
管道
收藏
收藏
0 条评论
下一页