Documentation

RdbImport
in package
uses RdbDumpTrait

Bulk import of data.

This uses the 'restore' command. Types and TTLs are preserved.

The input is expected to match that of RdbExport - a JSON-lines file, with base64 encoded values.

The gzip compression is auto-detected (if using file paths).

Attach a 'log' callback to track import progress and errors.

Tags
see
RdbExport

Table of Contents

Properties

$compressed  : bool
$errors  : array<string|int, string>
$excludes  : array<string|int, string>
$log  : callable|null
$pattern  : string
$rdb  : Rdb
$handle  : resource|null

Methods

__construct()  : mixed
Create a dumper for this rdb + pattern.
import()  : int
Import data that matches the 'pattern' into the DB.
isGzip()  : bool
Is this file a gzip?
read()  : Generator<int, array<string|int, mixed>>
Read all data from the file with the given 'pattern'.
setExclude()  : void
setLog()  : void
Set a logger callback.
setPattern()  : void
Set an include pattern.
close()  : void
Close ths file.
eof()  : bool
Is this file open?
gets()  : iterable<string|int, string|false>
Get all the lines from the file.
match()  : bool
open()  : void
Open a file in the given 'compression' mode.

Properties

$errors

public array<string|int, string> $errors = []

$excludes

public array<string|int, string> $excludes = []

Methods

__construct()

Create a dumper for this rdb + pattern.

public __construct(Rdb $rdb[, string|array<string|int, mixed> $config = [] ]) : mixed
Parameters
$rdb : Rdb
$config : string|array<string|int, mixed> = []
  • pattern (include pattern, default: '*')
  • excludes (array of patterns)
  • compressed (default: true)
  • log (callback)

Include + exclude patterns still respect the rdb's 'prefix'.

import()

Import data that matches the 'pattern' into the DB.

public import(string|resource $file) : int

If providing a file handle, please ensure the type matches the 'compressed' setting. Handles are not closed after writing.

Compressed files will be auto-detected if using a file path.

Parameters
$file : string|resource
Tags
throws
Exception

fatal errors, such as file access.

Return values
int —

The number of items imported.

isGzip()

Is this file a gzip?

public static isGzip(string $path) : bool
Parameters
$path : string
Return values
bool

read()

Read all data from the file with the given 'pattern'.

public read(string|resource $file) : Generator<int, array<string|int, mixed>>

This returns a 1-index key.

Parameters
$file : string|resource
Return values
Generator<int, array<string|int, mixed>> —

[ key, type, value ]

setExclude()

public setExclude(array<string|int, string>|string $pattern) : void
Parameters
$pattern : array<string|int, string>|string

setLog()

Set a logger callback.

public setLog(callable $log) : void
Parameters
$log : callable

setPattern()

Set an include pattern.

public setPattern(string $pattern) : void

Default is all keys - *.

Note, that this is still subject to the rdb's 'prefix'.

Parameters
$pattern : string

close()

Close ths file.

protected close() : void

Warning: only close your own files!

eof()

Is this file open?

protected eof() : bool
Return values
bool —

false if open, true if closed

gets()

Get all the lines from the file.

protected gets() : iterable<string|int, string|false>
Return values
iterable<string|int, string|false>

match()

protected match(string $key) : bool
Parameters
$key : string
Return values
bool

open()

Open a file in the given 'compression' mode.

protected open(string|resource $file, string $mode) : void

Note, gzip will auto-append the binary mode.

TODO add gzip compression 1-9 support.

Parameters
$file : string|resource
$mode : string
Tags
throws
Exception

if the file cannot be opened.

On this page

Search results