##########查看配置信息及当前存储的key值###########
[root@iZ113oau64sZ ~]# redis-cli [-h 127.0.0.1] [-p 6379]
127.0.0.1:6379> info
# Server
redis_version:3.2.1
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:534457225b137ffe
redis_mode:standalone
os:Linux 2.6.32-573.22.1.el6.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.7
process_id:7772
run_id:9544e674136eae52fe569eac24c7476b13effe8c
tcp_port:6379
uptime_in_seconds:15
uptime_in_days:0
hz:10
lru_clock:1145914
executable:/usr/local/redis/redis-server
config_file:/usr/local/redis/conf/redis.conf
# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:1182184
used_memory_human:1.13M
used_memory_rss:7819264
used_memory_rss_human:7.46M
used_memory_peak:1182184
used_memory_peak_human:1.13M
total_system_memory:8254705664
total_system_memory_human:7.69G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:6.61
mem_allocator:jemalloc-4.0.3
# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1477540907
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
# Stats
total_connections_received:1
total_commands_processed:1
instantaneous_ops_per_sec:0
total_net_input_bytes:31
total_net_output_bytes:5888248
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPU
used_cpu_sys:0.01
used_cpu_user:0.01
used_cpu_sys_children:0.00
used_cpu_user_children:0.00
# Cluster
cluster_enabled:0
# Keyspace
db0:keys=21,expires=0,avg_ttl=0
#########保存最新的key值################
127.0.0.1:6379> bgsave
Background saving started
##########查看是否保存成功##############
127.0.0.1:6379> lastsave
(integer) 1477541019
##########关闭redis服务器##############
redis-cli shutdown
#########查看Redis的RDB文件###########
[root@iZ113oau64sZ ~]# grep 'dir' /usr/local/redis/conf/redis.conf #查看RDB文件的存放位置
# The working directory.
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
# The Append Only File will also be created inside this directory.
# Note that you must specify a directory here, not a file name.
dir /usr/local/redis/db
# directive below) it is possible to tell the slave to authenticate before
# 2) Diskless: The Redis master creates a new process that directly writes the
# configuration directive.
# latency-monitor-threshold configuration directive. When its value is set
# threshold. These thresholds can be configured using the following directives.
# The syntax of every client-output-buffer-limit directive is the following:
[root@iZ113oau64sZ ~]# cd /usr/local/redis/db
##########压缩redis数据dump文件并拷入另一台机器#########
[root@iZ113oau64sZ ~]# tar -zcvf redis.tar.gz dump.rdb
[root@iZ113oau64sZ ~]# scp redis.tar.gz root@192.168.1.103:/usr/local/redis/db
#########登陆192.168.1.103机器并做相应配置#######
[root@iZ113oau64sZ ~]# vi /usr/local/redis/conf/redis.conf
dir /usr/local/redis/db #指定RDB文件路径
#########解压缩RDB文件##########################
[root@iZ113oau64sZ ~]# cd /usr/local/redis/db
[root@iZ113oau64sZ ~]# tar -zxvf redis.tar.gz
#########重启Redis服务器########################
[root@iZ113oau64sZ ~]# service redis restart
ps:
Redis–BGSAVE
在后台异步(Asynchronously)保存当前数据库的数据到磁盘。 BGSAVE 命令执行之后立即返回 OK ,然后 Redis fork 出一个新子进程,原来的 Redis 进程(父进程)继续处理客户端请求,而子进程则负责将数据保存到磁盘,然后退出。
客户端可以通过 LASTSAVE 命令查看相关信息,判断 BGSAVE 命令是否执行成功。
可用版本:>= 1.0.0时间复杂度:O(N), N 为要保存到数据库中的 key 的数量。返回值:反馈信息。
您可以选择一种方式赞助本站
支付宝扫一扫
微信扫一扫