redis笔记
参考 1
博客:Redis 通过 RDB 方式进行数据备份与还原 - WeihanLi - 博客园 (cnblogs.com)
github: Tags · redis/redis (github.com)
Redis 安装与常见操作
初识Redis(一):Redis简介及数据类型 - 简书 (jianshu.com)
Redis 下载与编译安装
wget https://github.com/redis/redis/archive/refs/tags/7.4.2.tar.gz
mkdir -p /tools/redis
mv 7.4.2.tar.gz /tools/redis/redis_7.4.2.tar.gz
cd /tools/redis
tar xf redis_7.4.2.tar.gz
cd /root/tools/redis/redis-7.4.2
mkdir -p /usr/local/redis
make distclean
make USE_SYSTEMD=yes -j8
make PREFIX=/usr/local/redis install
[root@VM-0-12-centos redis-7.4.2]# ll /usr/local/redis/bin
total 30108
-rwxr-xr-x 1 root root 6819824 Feb 9 18:04 redis-benchmark
lrwxrwxrwx 1 root root 12 Feb 9 18:04 redis-check-aof -> redis-server
lrwxrwxrwx 1 root root 12 Feb 9 18:04 redis-check-rdb -> redis-server
-rwxr-xr-x 1 root root 7801416 Feb 9 18:04 redis-cli
lrwxrwxrwx 1 root root 12 Feb 9 18:04 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 16207160 Feb 9 18:04 redis-server
[root@VM-0-12-centos redis-7.4.2]#
查看配置文件
[root@VM-0-12-centos redis-7.4.2]# pwd
/root/tools/redis/redis-7.4.2
[root@VM-0-12-centos redis-7.4.2]# grep -v '^#' redis.conf |grep -v '^$'
bind 127.0.0.1 -::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
locale-collate ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync yes
repl-diskless-sync-delay 5
repl-diskless-sync-max-replicas 0
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appenddirname "appendonlydir"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
aof-timestamp-enabled no
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-listpack-entries 512
hash-max-listpack-value 64
list-max-listpack-size -2
list-compress-depth 0
set-max-intset-entries 512
set-max-listpack-entries 128
set-max-listpack-value 64
zset-max-listpack-entries 128
zset-max-listpack-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
新建目录并修改配置文件
# 日志目录
mkdir -p /var/log/redis
# data 目录
mkdir -p /data/redis/data_6379
# pid 文件 /var/run/redis_6379.pid
# 构造配置文件
mkdir -p /etc/redis
cp redis.conf /etc/redis/redis_6379.conf
cat >> /etc/redis/redis_6379.conf <<-"EOF"
bind 127.0.0.1
port 6379
daemonize yes
pidfile /var/run/redis_6379.pid
logfile "/var/log/redis/redis_6379.log"
dir /data/redis/data_6379
appendonly no
appendfilename "appendonly.aof"
appenddirname "appendonlydir"
EOF
# 日志轮转
cat >> /etc/logrotate.d/redis_6379 <<-"EOF"
/var/log/redis/redis.log {
daily
rotate 7
compress
missingok
notifempty
copytruncate
}
EOF
构造服务启停脚本
cat >> /etc/init.d/redis_server <<-"EOF"
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO
REDISPORT=$1
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/redis_${REDISPORT}.conf"
case "$2" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
EOF
卸载
/etc/init.d/redis_server 6379 stop
rm -f /var/log/redis/redis_6379.log
rm -rf /data/redis/data_6379
rm -f /var/run/redis_6379.pid
rm -f /etc/redis/redis_6379.conf
Redis发布/订阅及事务
初识Redis(二):Redis发布/订阅及事务 - 简书 (jianshu.com)
Redis 备份与恢复
初识Redis(三):Redis数据备份、恢复与持久化 - 简书 (jianshu.com)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2018-02-09 文件导入到数据库