Redis Data Bulk Import Export

Source: Internet
Author: User
Tags redis
Redis Data Bulk Import Export

One way to do this is to export and import Redis data from one server to a new server in a work-redis-dump tool, but he needs to install a ruby environment, and there may be unexpected errors in the installation environment. So I have to choose another way. A few ideas for reference.

1, data export, do not write themselves, and do not use third-party scripts,
echo "Hgetall xxx" | Redis-cli-h localhost-p 6379
echo "Hgetall xxx" | Redis-cli-h localhost-p 6379 >> Wordlist.raw
2. As a result, you can view the Wordlist.raw file on the server
3. Organize the file format to enter
$f = ' xx.oo ';
$lines = 0;
$inkey = 0;
$rawfile = ' xx.oo ';
$hashkey = ' xx ';
$buff = ';
$fp = fopen ($rawfile, ' W ');
$fps = fopen ($f, ' R ');
while ($line = fgets ($fps)) {
 $inkey =! $inkey;
 if ($inkey) {
$f = ' Bayes_wordlist.raw ';
$lines = 0;
$inkey = 0;
$rawfile = ' Bayes_wordlist.3.raw ';
$hashkey = ' bayes_wordlist ';
$buff = ';
$fp = fopen ($rawfile, ' W ');
$fps = fopen ($f, ' R ');
while ($line = fgets ($fps)) {
 $inkey =! $inkey;
 if ($inkey) {
  $line = sprintf ('%s ', trim ($line));
  $buff = "Hset $hashkey". Trim ($line);
 else
 {
  $buff. = ' "'. Trim ($line).
  Fwrite ($FP, $buff. " \ r \ n ");
 }
}
  $buff = "Hset $hashkey". Trim ($line);
 else
 {
  $buff. = ' "'. Trim ($line).
  Fwrite ($FP, $buff. " \ r \ n ");
 }
}


If you choose which library to write to select X on the first line
4. Using REDIS-CLI to import
echo ' Date ' > Pipe.log && cat xx.oo | REDIS-CLI >> pipe.log && echo ' Date ' >> pipe.log
5. Add a time record, and record the results of the import, the actual execution of the import statement is
Cat Wordlist.raw | REDIS-CLI, of course, more rigorous words redis-cli after also add-H localhost-p 6379 parameters.
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.