Redis
2021-08-03 10:51:28 7 举报
AI智能生成
Redis
作者其他创作
大纲/内容
Redis
安装
linux
ubuntu
sudo apt install redis-server# 启动redis-server# 连接redis-cli
wget http://download.redis.io/releases/redis-6.0.8.tar.gztar xzf redis-6.0.8.tar.gzcd redis-6.0.8make# 启动cd src./redis-server ../redis.conf 或 ./redis-server# 连接./redis-cli
mac
windows
https://github.com/tporadowski/redis/releases# 启动redis-server.exe redis.windows.conf# 连接redis-cli.exe -h 127.0.0.1 -p 6379
数据类型
String
Hash
List
Set
Sorted Set | zset
Shell
连接
redis-cli [OPTIONS]
性能测试
redis-benchmark [OPTIONS]
命令
Key
过期时间
EXPIRE key seconds
EXPIREAT key timestamp
\tPEXPIRE key milliseconds
PEXPIREAT key milliseconds-timestamp
PERSIST key
PTTL key
TTL key
重命名
RENAME key newkey
RENAMENX key newkey
DEL key
DUMP key
RANDOMKEY
TYPE key
EXISTS key
MOVE key db
\tKEYS pattern
SCAN cursor [MATCH pattern] [COUNT count]
设置
SET key value
SETBIT key offset value
SETEX key seconds value
PSETEX key milliseconds value
SETNX key value
SETRANGE key offset value
MSET key value [key value ...]
MSETNX key value [key value ...]
获取
GET key
GETRANGE key start stop
GETSET key value
GETBIT key offset
MGET key1 [key2..]
自增
INCR key
INCRBY key increment
INCRBYFLOAT key increment
自减
DECR key
DECRBY key decrement key
STRLEN key
APPEND key value
HSET key field value
HSETNX key field value
HMSET key field1 value1 [field2 value2 ]
HGET key field
HGETALL key
HMGET key field1 [field2]
HINCRBY key field increment
HINCRBYFLOAT key field increment
HDEL key field1 [field2]
HEXISTS key field
HKEYS key
HVALS key
HLEN key
HSCAN key cursor [MATCH pattern] [COUNT count]
LSET key index value
LINDEX key index
LRANGE key start stop
删除
LTRIM key start stop
BRPOPLPUSH source destination timeout
RPOPLPUSH source destination
LREM key count value
首
LPOP key
BLPOP key1 [key2 ] timeout
尾
RPOP key
BRPOP key1 [key2 ] timeout
插入
LINSERT key BEFORE|AFTER pivot value
LPUSH key value1 [value2]
LPUSHX key value
RPUSH key value1 [value2]
RPUSHX key value
LLEN key
差集
SDIFF key1 [key2]
SDIFFSTORE destination key1 [key2]
交集
SINTER key1 [key2]
SINTERSTORE destination key1 [key2]
并集
SUNION key1 [key2]
SUNIONSTORE destination key1 [key2]
SPOP key
SREM key member1 [member2]
SADD key member1 [member2]
SCARD key
SISMEMBER key member
SMEMBERS key
SMOVE source destination member
SRANDMEMBER key [count]
SSCAN key cursor [MATCH pattern] [COUNT count]
ZADD key score1 member1 [score2 member2]
ZRANK key member
ZSCORE key member
ZRANGE key start stop [WITHSCORES]
ZRANGEBYLEX key min max [LIMIT offset count]
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT]
ZREVRANGE key start stop [WITHSCORES]
ZREVRANGEBYSCORE key max min [WITHSCORES]
ZREVRANK key member
ZREM key member [member ...]
ZREMRANGEBYLEX key min max
ZREMRANGEBYRANK key start stop
ZREMRANGEBYSCORE key min max
长度
ZCARD key
ZLEXCOUNT key min max
ZCOUNT key min max
ZINCRBY key increment member
ZINTERSTORE destination numkeys key [key ...]
ZUNIONSTORE destination numkeys key [key ...]
ZSCAN key cursor [MATCH pattern] [COUNT count]
HyperLogLog
PFADD key element [element ...]
PFCOUNT key [key ...]
PFMERGE destkey sourcekey [sourcekey ...]
发布订阅
PUBSUB subcommand [argument [argument ...]]
PUBLISH channel message
订阅
SUBSCRIBE channel [channel ...]
PSUBSCRIBE pattern [pattern ...]
退订
UNSUBSCRIBE [channel [channel ...]]
PUNSUBSCRIBE [pattern [pattern ...]]
事务
开始
MULTI
监视
UNWATCH
WATCH key [key ...]
结束
EXEC
DISCARD
管道
分区
范围分区
哈希分区
脚本
EVAL script numkeys key [key ...] arg [arg ...]
EVALSHA sha1 numkeys key [key ...] arg [arg ...]
SCRIPT FLUSH
SCRIPT KILL
SCRIPT LOAD script
SCRIPT EXISTS script [script ...]
AUTH password
ECHO message
PING
QUIT
SELECT index
客户端
CLIENT GETNAME
CLIENT SETNAME connection-name
CLIENT LIST
CLIENT KILL [ip:port] [ID client-id]
CLIENT PAUSE timeout
服务器
COMMAND
COMMAND COUNT
COMMAND GETKEYS
COMMAND INFO command-name [command-name ...]
配置
CONFIG GET parameter
CONFIG REWRITE
CONFIG SET parameter value
CONFIG RESETSTAT
数据库
DBSIZE
FLUSHALL
FLUSHDB
DEBUG OBJECT key
异步
BGREWRITEAOF
BGSAVE
SHUTDOWN [NOSAVE] [SAVE]
TIME
INFO [section]
MONITOR
DEBUG SEGFAULT
LASTSAVE
ROLE
SAVE
CLUSTER SLOTS
SLAVEOF host port
SLOWLOG subcommand [argument]
SYNC
GEO
GEOADD key longitude latitude member [longitude latitude member ...]
GEOPOS key member [member ...]
GEODIST key member1 member2 [m|km|ft|mi]
GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD|WITHDIST|WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]
GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]
GEOHASH key member [member ...]
Stream
消息队列
XADD
XADD key ID field value [field value ...]
XTRIM
XTRIM key MAXLEN [~] count
XDEL
XDEL key ID [ID ...]
XLEN
XLEN key
XRANGE
XRANGE key start end [COUNT count]
XREVRANGE
XREVRANGE key end start [COUNT count]
XREAD
XREAD [COUNT count] [BLOCK milliseconds] STREAMS key [key ...] id [id ...]
消费者组
XGROUP CREATE
XGROUP [CREATE key groupname id-or-$] [SETID key groupname id-or-$] [DESTROY key groupname] [DELCONSUMER key groupname consumername]
XREADGROUP GROUP
XREADGROUP GROUP group consumer [COUNT count] [BLOCK milliseconds] [NOACK] STREAMS key [key ...] ID [ID ...]
XACK
XGROUP SETID
XGROUP DELCONSUMER
XGROUP DESTROY
XPENDING
XCLAIM
XINFO
XINFO GROUPS
XINFO STREAM
数据备份与恢复
备份
SAVE
Bgsave
恢复
1. 将备份文件 (dump.rdb) 移动到 redis 安装目录并启动服务2. CONFIG GET dir
安全
验证
CONFIG SET requirepass password
CONFIG GET requirepass
配置文件
路径
redis.conf
redis.windows.conf
参数
daemonize no
pidfile /var/run/redis.pid
port 6379
bind 127.0.0.1
timeout 300
loglevel notice
logfile stdout
databases 16
save <seconds> <changes>
rdbcompression yes
dbfilename dump.rdb
dir ./
slaveof <masterip> <masterport>
masterauth <master-password>
requirepass foobared
maxclients 128
maxmemory <bytes>
appendonly no
appendfilename appendonly.aof
appendfsync everysec
vm-enabled no
vm-swap-file /tmp/redis.swap
vm-max-memory 0
vm-page-size 32
vm-pages 134217728
vm-max-threads 4
glueoutputbuf yes
hash-max-zipmap-entries 64hash-max-zipmap-value 512
activerehashing yes
include /path/to/local.conf
接口
0 条评论
回复 删除
下一页