-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsv2redis.pl
50 lines (45 loc) · 1.14 KB
/
tsv2redis.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/env perl
#
use strict;
use warnings;
use Redis::Client;
use JSON;
$#ARGV<1 and die"$0 hashName db.tsv keyIndex\n";
# redis server
#my$host="192.168.136.114";
my$host="127.0.0.1";
my$port=6379;
print STDERR scalar localtime(),"\tstart redis client\n";
my$client=Redis::Client->new(host=>$host,port=>$port);
#my$hashName="native_snp";
my$hashName=shift;
my$tsv=shift;
my$keyIndex=shift;
defined$keyIndex or $keyIndex=0;
my@keyIndex=split /,/,$keyIndex;
open IN,"zcat -f $tsv|" or die$!;
my%hash;
my$count=0;
my$totalCount=0;
print STDERR scalar localtime(),"\tstart update db to redis\n";
while(<IN>){
chomp;
my@ln=split /\t/,$_;
my$key=join("_",@ln[@keyIndex]);
$hash{$key}=to_json(\@ln);
$count++;
if($count>=524287){
$client->hmset($hashName,%hash) or die$!;
$totalCount+=$count;
print STDERR scalar localtime(),"\tupdate $totalCount($count) record\n";
$count=0;
%hash=();
}
# $client->hset($hashName,$key=>$hash{$key});
}
close IN;
$count
and $client->hmset($hashName,%hash) or die$!;
$totalCount+=$count;
print STDERR scalar localtime(),"\tupdate $totalCount($count) record\n";
print STDERR scalar localtime(),"\tupdate redis done\n";