包括
包括
优点
解压软件包——make && make install——设置Redis相关配置文件——查看运行状态
yum -y install gcc gcc-c++ make
tar zxvf redis-5.0.7.tar.gz
cd redis-5.0.7/
make
make PREFIX=/usr/local/redis install
cd /usr/local/redis/
ln -s /usr/local/redis/bin/* /usr/local/bin/
cd /opt/redis-5.0.7/utils/
./install_server.sh
一路回车
Please select the executable path [/usr/local/bin/redis-server] /usr/local/redis/bin/redis-server //手动输入
*************** Redis 进程控制**********************
/etc/init.d/redis_6379 status
/etc/init.d/redis_6379 stop
/etc/init.d/redis_6379 start
vim /etc/6379.conf
redis-cli //登录
bind:监听的主机地址
port:端口
daemonize yes:启用守护进程
pidfile:指定PID文件
loglevel notice:日志级别
logfile:指定日志文件
返回值1 为操作成功,返回值为0操作失败
[root@localhost utils]# /usr/local/redis/bin/redis-cli
127.0.0.1:6379>
[root@localhost utils]# redis-cli -h 192.168.10.161 -p 6379
192.168.10.161:6379>
[root@localhost utils]# /usr/local/redis/bin/redis-cli
127.0.0.1:6379> help @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
……
127.0.0.1:6379> help set
SET key value [EX seconds] [PX milliseconds] [NX|XX]
summary: Set the string value of a key
since: 1.0.0
group: string
[root@localhost ~]# /usr/local/redis/bin/redis-cli
127.0.0.1:6379> set teacher zhanglong
OK
127.0.0.1:6379> get teacher
"zhanglong"
127.0.0.1:6379> set cname tt
OK
127.0.0.1:6379> keys *
1) "cname"
127.0.0.1:6379[3]> set ttyy aa
OK
127.0.0.1:6379[3]> exists ttyy
(integer) 1
127.0.0.1:6379[3]>
127.0.0.1:6379> set cname aa
OK
127.0.0.1:6379> keys *
1) "cname"
127.0.0.1:6379> exists cname
(integer) 1
127.0.0.1:6379> del cname
(integer) 1
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379[3]> set ttyy aa
OK
127.0.0.1:6379[3]> type ttyy
string
127.0.0.1:6379[3]> rename ttyy zznn
OK
127.0.0.1:6379[3]> keys *
1) "zznn"
127.0.0.1:6379[3]>
127.0.0.1:6379[3]> keys *
1) "zznn"
127.0.0.1:6379[3]> dbsize
(integer) 1
127.0.0.1:6379[3]>
其他常用redis命令
flushdb '//清空库'
192.168.79.133:6379> move uuu 11 '//将uuu键值对移动到第12个库'
(integer) 1
-h:指定服务器主机名
-p:指定服务器端口
-c:指定并发连接数
-n:指定请求数
-d:以字节的形式指定SET/GET值的数据大
向IP地址为192.168.75.134、端口为6379的Redis服务器发送100个并发连接与100000个请求测试性能
[root@localhost redis]# /usr/local/redis/bin/redis-benchmark -h 192.168.75.134 -p 6379 -c 100 -n 100000
====== PING_INLINE ======
100000 requests completed in 0.89 seconds
100 parallel clients
3 bytes payload
keep alive: 1
98.42% <= 1 milliseconds
100.00% <= 2 milliseconds
112107.62 requests per second
====== PING_BULK ======
100000 requests completed in 0.91 seconds
100 parallel clients
3 bytes payload
keep alive: 1
98.20% <= 1 milliseconds
99.91% <= 2 milliseconds
100.00% <= 3 milliseconds
100.00% <= 3 milliseconds
109649.12 requests per second
====== SET ======
100000 requests completed in 0.96 seconds
100 parallel clients
3 bytes payload
keep alive: 1
96.26% <= 1 milliseconds
99.65% <= 2 milliseconds
99.93% <= 3 milliseconds
99.94% <= 4 milliseconds
99.99% <= 5 milliseconds
100.00% <= 5 milliseconds
103626.95 requests per second
====== GET ======
100000 requests completed in 0.99 seconds
100 parallel clients
3 bytes payload
keep alive: 1
95.36% <= 1 milliseconds
99.67% <= 2 milliseconds
99.99% <= 3 milliseconds
100.00% <= 3 milliseconds
100704.94 requests per second
[root@localhost redis]# /usr/local/redis/bin/redis-benchmark -h 192.168.75.134 -p 6379 -q -d 100
PING_INLINE: 120481.93 requests per second
PING_BULK: 120627.27 requests per second
SET: 118063.76 requests per second
GET: 118483.41 requests per second
INCR: 118623.96 requests per second
LPUSH: 115473.45 requests per second
RPUSH: 116822.43 requests per second
LPOP: 116009.28 requests per second
RPOP: 116686.12 requests per second
SADD: 119904.08 requests per second
HSET: 120481.93 requests per second
SPOP: 118623.96 requests per second
LPUSH (needed to benchmark LRANGE): 119474.31 requests per second
LRANGE_100 (first 100 elements): 52938.06 requests per second
LRANGE_300 (first 300 elements): 21810.25 requests per second
LRANGE_500 (first 450 elements): 12210.01 requests per second
LRANGE_600 (first 600 elements): 8411.14 requests per second
MSET (10 keys): 101626.02 requests per second
优缺点
在指定的时间间隔内,执行指定次数的写操作(配置文件控制)
执行save或者是bgsave (异步)命令
执行flushall 命令,清空数据库所有数据高危命令
执行shutdown 命令,保证服务器正常关闭且不丢失任何数据
配置文件选项
vim /etc/redis/6379.conf
save 900 1
save 300 10
save 60 10000
dbfilename dump.rdb
dir /var/lib/redis/6379
rdbcompression yes
save 900 1
save 300 10
save 60 10000
dir /var/lib/redis/6379 ##RDB文件路径
rdbcompression yes ##是否进行压缩
配置文件选项
vim /etc/redis/6379.conf
appendonly yes ##开启AOF持久化
appendfilename "appendonly.aof " ##AOF文件名称
# appendfsync always
appendfsync everysec
##always:同步持久化,每次发生数据变化会立刻写入磁盘
##everysec:默认推荐,每秒异步记录一次(默认值)
##no:不同步,交给操作系统决定如何同步
# appendfsync no
aof-load-truncated yes ##忽略最后一条可能存在问题的指令
vim /etc/redis/6379.conf
# 在日志进行BGREWRITEAOF时,如果设置为yes表示新写操作不进行同步fsync,只是暂存在缓冲区里,避免造成磁盘IO操作冲突,等重写完成后在写入。Redis中默认为no
no-appendfsync-on-rewrite no
# 当前AOF文件大小是上次日志重写时AOF文件大小两倍时,发生BGREWRITEAOF操作
auto-aof-rewrite-percentage 100
#当前AOF文件执行BGREWRITEAOF命令的最小值,避免刚开始启动Reids时由于文件尺寸较小导致频繁的BGREWRITEAOF
auto-aof-rewrite-min-size 64mb
[root@master1 ~]# /usr/local/redis/bin/redis-cli
127.0.0.1:6379> info memory
[root@localhost redis]# redis-cli
127.0.0.1:6379> info memory
# Memory
used_memory:11768208
used_memory_human:11.22M ##内存的使用
used_memory_rss:26865664
used_memory_rss_human:25.62M
used_memory_peak:25172352
used_memory_peak_human:24.01M
used_memory_peak_perc:46.75%
used_memory_overhead:841542
used_memory_startup:791400
used_memory_dataset:10926666
used_memory_dataset_perc:99.54%
allocator_allocated:12203688
allocator_active:12582912
allocator_resident:21553152
total_system_memory:4254142464
total_system_memory_human:3.96G
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.03
allocator_frag_bytes:379224
allocator_rss_ratio:1.71
allocator_rss_bytes:8970240
rss_overhead_ratio:1.25
rss_overhead_bytes:5312512
mem_fragmentation_ratio:2.29 ##内存的碎片率
mem_fragmentation_bytes:15138480
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:49694
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0