Redis uses Persistence for data migration

Source: Internet
Author: User
Tags redis cluster install redis

Redis uses Persistence for data migration

Preface

Redis is an open-source high-performance Key-Value Pair database. It provides a variety of key-value data types to meet the storage needs in different scenarios, and uses many high-level interfaces to make it competent for different roles such as cache and Queue Systems.

Redis persistence

To improve performance, Redis stores all data in the memory by default. However, when the server is restarted or the program crashes abnormally, all Redis data will be lost. Therefore, the concept of persistence emerged. Persistence is to synchronize data in memory to the disk to ensure persistence.

1. Redis persistence
Two types: RDB and AOF

RDB persistence allows you to generate a point-in-time snapshot of a dataset within a specified interval ).

AOF records all write operation commands executed by the server persistently, and re-executes these commands to restore the dataset when the server starts. All commands in the AOF file are saved in the format of the Redis protocol. The new commands are appended to the end of the file. Redis can also rewrite the AOF file in the background so that the size of the AOF file does not exceed the actual size required to save the dataset status.

2. What is the use of persistent data?
It is used to recover data after restart. Redis is an in-memory database. Both RDB and AOF are measures to ensure data recovery. Therefore, Redis reads the RDB or AOF files during recovery using RDB and AOF, reload to the memory.

Default persistence

RDB is the point-in-time snapshot storage, which is also the default persistence method. RDB can be understood as a semi-persistent mode, that is, the data is periodically stored to the disk according to certain policies. The corresponding data file is dump. rdb. the snapshot cycle is defined by the save parameter in the configuration file. The RDB file of Redis will not be broken because the write operation is performed in a new process.

Default persistence settings:
Save 900 1 # When a Keys data item is changed, it is refreshed to Disk once every 900 seconds.
Save 300 10 # When 10 pieces of Keys data are changed, refresh to Disk once every 300 seconds
Save 60 10000 # When 10000 pieces of Keys data are changed, refresh to Disk once every 60 seconds

Using persistent data migration
######### View configuration information and the key value of the current storage ###########
[Root @ web-yv2 ~] # Redis-cli-h 10.160.35.86-p 6379
Redis 10.160.35.86: 6379> info
Redis_version: 2.4.10
Redis_git_sha1: 00000000
Redis_git_dirty: 0
Arch_bits: 64
Multiplexing_api: epoll
Gcc_version: 4.4.6
Process_id: 11911
Uptime_in_seconds: 2154256
Uptime_in_days: 24
Lru_clock: 1527581
Used_cpu_sys: 1145.31
Used_cpu_user: 1430.18
Used_cpu_sys_children: 56.20
Used_cpu_user_children: 207.71
Connected_clients: 147
Connected_slaves: 0
Client_longest_output_list: 0
Client_biggest_input_buf: 0
Blocked_clients: 12
Used_memory: 6762928
Used_memory_human: 6.45 M
Used_memory_ RSS: 19816448
Used_memory_peak: 10441776
Used_memory_peak_human: 9.96 M
Mem_fragmentation_ratio: 2.93
Mem_allocator: jemalloc-2.2.5
Loading: 0
Aof_enabled: 0
Changes_since_last_save: 166
Bgsave_in_progress: 0
Last_save_time: 1420367541
Bgrewriteaof_in_progress: 0
Total_connections_received: 1387982
Total_commands_processed: 25568539
Expired_keys: 1838499
Evicted_keys: 0
Keyspace_hits: 529489
Keyspace_misses: 1838207
Pubsub_channels: 0
Pubsub_patterns: 0
Latest_fork_usec: 947
Vm_enabled: 0
Role: master
Db0: keys = 18255, expires = 17326
######## Save the latest key value ################
Redis 10.160.35.86: 6379> BGSAVE
Background saving started
########## Check whether the storage is successful ##############
Redis 10.160.35.86: 6379> LASTSAVE
(Integer) 1420367903
########## Disable the redis server ##############
Redis-cli-h 10.160.35.86-p 6379 SHUTDOWN
######## View the Redis RDB file ###########
[Root @ web-yv2 ~] # Grep "dir"/etc/redis. conf # view the location of the RDB File
# The working directory.
# The DB will be written inside this directory, with the filename specified
# Above using the 'dbfilename' configuration ctive ve.
# Also the Append Only File will be created inside this directory.
# Note that you must specify a directory here, not a file name.
Dir/var/lib/redis/# store the RDB file here
# Directive below) it is possible to tell the slave to authenticate before
# Using the following configuration directive.
# The swap file under/tmp is not secure. Create a dir with access granted
# Configuration ctictives.
[Root @ web-yv2 ~] # Find/-name dump. rdb # find the dump file
/Var/lib/redis/dump. rdb
######### Compress the redis file and merge it to another machine #########
[Root @ web-yv2 ~] # Tar zcvf redis.tar.gz/var/lib/redis
[Root @ web-yv2 ~] # Scp redis.tar.gz root@10.160.35.67:/var/lib/
######## Log on to the 10.160.35.67 host and configure it #######
[Root @ web-yv1 ~] # Vi/etc/redis. conf
Dir/var/lib/redis/# specify the RDB file path
######### Decompress the RDB file ##########################
[Root @ web-yv1 ~] # Cd/var/lib/
[Root @ web-yv1 ~] # Tar xf redis.tar.gz
######### Restart the Redis server ########################
[Root @ web-yv1 ~] # Service redis restart

Additional information

Redis-BGSAVE
Asynchronously saves the data of the current database to the disk in the background (Asynchronously.
After the BGSAVE command is executed, the system immediately returns OK, and Redis fork generates a new sub-process. The original Redis process (parent process) continues to process client requests, the child process is responsible for saving the data to the disk and then exiting.
The client can use the LASTSAVE command to view related information and determine whether the BGSAVE command is successfully executed.
Please go to the persistent document to view more details.
Available version:> = 1.0.0 time complexity: O (N), N is the number of keys to be saved to the database. Return Value: feedback information.
Redis> BGSAVE
Background saving started

Redis-LASTSAVE
LASTSAVE
Returns the last time Redis successfully saved data to the disk, expressed in UNIX timestamp format.
Available version:> = 1.0.0 time complexity: O (1) Return Value: a unix timestamp.
Redis> LASTSAVE
(Integer) 1324043588

Install and test Redis in Ubuntu 14.04

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

Redis details: click here
Redis: click here

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.