NAME
Redis::AOF::Tail::File - Read redis aof file in realtime
SYNOPSIS
use Redis::AOF::Tail::File;
my $aof_file = "/var/redis/appendonly.aof";
my $redis_aof = Redis::AOF::Tail::File->new(aof_filename => $aof_file);
while (my $cmd = $redis_aof->read_command)
{
print "[$cmd]\n";
}
DESCRIPTION
This extension can be used for synchronous data asynchronously from redis to MySQL. Maybe you can code like below.
use DBI;
use Redis::AOF::Tail::File;
use Storable qw(retrieve store);
# variables in this comment should be defined
# $data_source, $username, $auth, \%attr,
# some_func_translate_redis_command_to_sql()
my $dbh = DBI->connect($data_source, $username, $auth, \%attr);
my $aof_file = "/var/redis/appendonly.aof";
my $seek_stor_file = "/var/redis/seek_stor_file";
my $aof_seek_pos = 'eof';
$aof_seek_pos = ${retrieve $seek_stor_file} if -s $seek_stor_file;
my $redis_aof = Redis::AOF::Tail::File->new(aof_filename => $aof_file, seekpos => $aof_seek_pos);
while (my ($pos, $cmd) = $redis_aof->read_command)
{
my $sql = some_func_translate_redis_command_to_sql($cmd);
store \$pos, $seek_stor_file if $dbh->do($sql);
}
METHODS
new()
There are two forms of new().
1.Normal form.
my $redis_aof = Redis::AOF::Tail::File->new(aof_filename => $aof_file);
2.Read from the seekpos.
my $redis_aof = Redis::AOF::Tail::File->new(aof_filename => $aof_file, seekpos => $aof_seek_pos);
read_command()
There are two forms of this method is called.
1. my $cmd = $redis_aof->read_command()
you got the redis command in $cmd.
2. my ($pos, $cmd) = $redis_aof->read_command().
you got redis command in $cmd, and read position in $pos.
EXPORT
None by default.
SEE ALSO
AUTHOR
Chen Gang, <[email protected]>
COPYRIGHT AND LICENSE
Copyright (C) 2014 by Chen Gang
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16.2 or, at your option, any later version of Perl 5 you may have available.