Migrate some redis data to other redis instances

Source: Internet
Author: User
Some time ago, we found that the redis memory usage on one of our business servers exceeds 50% of the total server memory. When bgsave is triggered, an error is reported, prompting WARNINGovercommit_memoryissetto0 !..., Then all redis write operations will fail. In this case, there is a solution in the redis official FAQ. in linux, perform the following operations, ec

Some time ago, we found that the redis memory usage on one of our business servers exceeds 50% of the total server memory. When bgsave is triggered, an error is reported, prompting WARNING overcommit_memory is set to 0! ..., And then all redis write operations will fail. In this case, there is a solution in the redis official FAQ. in linux, perform the following operations, ec

Some time ago, we found that the memory usage of redis on one of our business servers exceeds 50% of the total server memory. When bgsave is triggered, an error is reported, promptingWARNING overcommit_memory is set to 0! ...And all redis write operations will fail. In this case, there is a solution in the redis official FAQ. in linux, perform the following operations,

echo 1 > /proc/sys/vm/overcommit_memory

Specific can see the official FAQ, http://redis.io/topics/faq

After resolving the bgsave problem, we decided to migrate a part of the data to another redis instance and record the migration process below. One of the two solutions is to copy the rdb file or configure a synchronization from redis, but all the data has been migrated and other processing is required. Another solution is to write a migration script to migrate only part of the data to be migrated.

Paste it here

#! /Bin/bash # redis source ipsrc_ip = 192.168.0.10 # redis source portsrc_port = 6379 # redis destination ipdest_ip = 192.168.0.11 # redis destination portdest_port = 6379 # key prefix key_prefix = com. example. testi = 1redis-cli-h $ src_ip-p $ src_port keys "$ {key_prefix} *" | while read keydo redis-cli-h $ dest_ip-p $ dest_port del $ key redis-cli -h $ src_ip-p $ src_port -- raw dump $ key | perl-pe 'chomp if eof '| redis-cli-h $ dest_ip-p $ dest_port-x restore $ key 0 echo "$ I migrate key $ key" (I ++ )) done

References:

1. http://redis.io/commands/DUMP

2. http://stackoverflow.com/questions/16127682/how-to-use-redis-dump-and-restore-offline

Original article address: migrate some redis data to other redis instances. Thanks to the original author for sharing.

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.