Skip to content

perlamutr/php-rdb-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis dump file (RDB) parser

Latest Stable Version Total Downloads Latest Unstable Version License

PHP Implementation of Redis RDB parser

Installation

Use composer :

composer require perlamutr/php-rdb-parser

Usage

All you need is two objects: ReaderFile to read from rdb-file and Parser to fetch its keys and values

<?php
use Perlamutr\Reader\ReaderFile;
use Perlamutr\Parser;

$reader = new ReaderFile('filename.rdb');
$parser = new Parser($reader);
$generator = $parser->parseRDB();

foreach ($generator as $key => $value) {
    if (is_object($key)) {
        //  if parser meets command it returns $key as object of type Command
        continue;
    }
    //  Otherwise it contains the key
    echo "Key = '$key'\n";
    //  And value is a Generator with key-value pairs (or single value)
    foreach ($value as $k => $v) {
        echo "\t$k => $v\n";
    }
}

If may call setSkipData before parseRDB method with true argument. Parser will skip as much as he can and will return Generator with keys and additional information for each of them such as wasted bytes, type of key and file position

<?php
use Perlamutr\Reader\ReaderFile;
use Perlamutr\Parser;

$reader = new ReaderFile('filename.rdb');
$parser = new Parser($reader);
$parser->setSkipData(true);
$generator = $parser->parseRDB();
foreach ($generator as $key => $value) {
    //  $key is always string with key name
    echo "Key = '$key'\tType = '{$value['type']}\tBytes = '{$value['skip']}'\tPosition = '{$value['position']}'\n";    
}

About

Redis RDB file parser in pure PHP

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages