FengGu(冯 顾) > Redis-RdbParser-0.02 > Redis::RdbParser

Download:
Redis-RdbParser-0.02.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.02   Source   Latest Release: Redis-RdbParser-0.05

NAME ^

Redis::RdbParser - Redis rdb dump file parser

VERSION ^

version 0.02

SYNOPSIS ^

 use Redis::RdbParser;

 $parser = new Redis::RdbParser;
 # or
 my $callbacks = {
     "start_rdb"         => \&start_rdb,
     "start_database"    => \&start_database,
     "key"               => \&key,
     "set"               => \&set,
     "start_hash"        => \&start_hash,
     "hset"              => \&hset,
     "end_hash"          => \&end_hash,
     "start_set"         => \&start_set,
     "sadd"              => \&sadd,
     "end_set"           => \&end_set,
     "start_list"        => \&start_list,
     "rpush"             => \&rpush,
     "end_list"          => \&end_list,
     "start_sorted_set"  => \&start_sorted_set,
     "zadd"              => \&zadd,
     "end_sorted_set"    => \&end_sorted_set,
     "end_database"      => \&end_database,
     "end_rdb"           => \&end_rdb,
 };
 $parser = new Redis::RdbParser($callback);

 $parser->parse($filename);
 # or 
 my $filter = {
     'dbs' => [0, 1],
     'keys' => ["^foo$", "^bar"],
     'types' => ["hash", "set"],
 };
 $parser->parse($filename, $filter);

DESCRIPTION ^

Redis::RdbParser is a parser for Redis' rdb dump files. The parser generates events similar to an xml sax parser.

callbacks

The dump file is parsed sequentially. As and when objects are discovered, appropriate callbacks would be invoked. You can set the callback item `undef` if you don't care it.

start_rdb
    sub start_rdb {
        my $filename = shift;
        # fill your code
    }

Called once we know we are dealing with a valid Redis dump file.

start_database
    sub start_database {
        my $db_number = shift;
        # fill your code
    }

Called to indicate the start of database `db_number`. Once a database starts, another database cannot start unless the first one completes and then `end_database` callback is called.

key
    sub key {
        my $key = shift;
        # fill your code
    }

Called to indicate a key readed in the parsing process.

set
    sub set {
        my ($key, $value, $expiry) = @_;
        # fill your code
    }

Callback to handle a key with a string value and an optional expiry.

start_hash
    sub start_hash {
        my ($key, $length, $expiry, $info) = @_;
        # fill your code
    }

Callback to handle the start of a hash.

After `start_hash`, the callback `hset` will be called with this `key` exactly `length` times.

After that, the `end_hash` callback will be called.

hset
    sub hset {
        my ($key, $field, $value) = @_;
        # fill your code
    }

Callback to insert a field=value pair in an existing hash.

end_hash
    sub end_hash {
        my $key = shift;
        # fill your code
    }

Called when there are no more elements in the hash.

start_set
    sub start_set {
        my ($key, $length, $expiry, $info) = @_;
        # fill your code
    }

Callback to handle the start of the set.

After `start_set`, the callback `sadd` will be called with `key` exactly `length` times.

After that, the callback `end_set` will be called to indicate the end of the set.

sadd
    sub sadd {
        my ($key, $member) = @_;
        # fill your code
    }

Callback to insert a new member to this set.

end_set
    sub end_set {
        my ($key) = @_;
        # fill your code
    }

Called when there are no more elements in this set.

start_list
    sub start_list {
        my ($key, $length, $expiry, $info) = @_;
        # fill your code
    }

Callback to handle the start of a list.

After `start_list`, the callback `rpush` will be called with `key` exactly `length` times.

After that, the `end_list` method will be called to indicate the end of the list.

rpush
    sub rpush {
        my ($key, $value) = @_;
        # fill your code
    }

Callback to insert a new value into this list.

end_list
    sub end_list {
        my ($key) = @_;
        # fill your code
    }

Called when there are no more elements in this list.

start_sorted_set
    sub start_sorted_set {
        my ($key, $length, $expiry) = @_;
        # fill your code
    }

Callback to handle the start of a sorted set.

After `start_sorted_set`, the callback `zadd' will called with `key` exactly `length` times.

Also, `zadd` will be called in a sorted order, so as to preserve the ordering of this sorted set.

After that, the callback `end_sorted_set` will be called to indicate the end of this sorted set.

zadd
    sub zadd {
        my ($key, $score, $member) = @_;
        # fill your code
    }

Callback to insert a new value into this sorted set.

end_sorted_set
    sub end_sorted_set {
        my ($key) = @_;
        # fill your code
    }

Called when there are no more elements in this sorted set.

end_database
    sub end_database {
        my $db_number = shift;
        # fill your code
    }

Called when the current database ends

After `end_database`, one of the callbacks are called:

1) `start_database` with a new database number

2) `end_rdb` to indicate we have reached the end of the file

end_rdb
    sub end_rdb {
        my $filename = shift;
        # fill your code
    }

Called to indicate we have completed parsing of the dump file.

filter

filter is a reference with the following keys:

    $filter = {
        "dbs"   => [0, 1],              # db number
        "keys"  => ["^foo$", "^bar"],   # keys regular expression
        "types" => ["string", "hash", "list", "set", "sorted set"],
    }

If filter is undef, results will not be filtered. If dbs, keys or types is undef, no filtering will be done on the axis.

REPOSITORY ^

https://github.com/flygoast/Redis-RdbParser

AUTHOR ^

fenggu, <flygoast@126.com>

COPYRIGHT AND LICENSE ^

Copyright (C) 2012 by fenggu

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: