RdbExport
in package
uses
RdbDumpTrait
Bulk export of data.
This uses the 'dump' command. Types and TTLs are preserved.
The output format is a JSON-lines file, with base64 encoded values.
By default the file will be gzip compressed.
[ key1, ttl, base64 ]\n
[ key2, ttl, base64 ]\n
[ key3, ttl, base64 ]\n
...
Attach a 'log' callback to track export progress and errors.
Tags
Table of Contents
Properties
- $compressed : bool
- $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.
- export() : int
- Export all data from the DB with the 'pattern' into this file.
- isGzip() : bool
- Is this file a gzip?
- read() : Generator<int, array<string|int, mixed>>
- Read all data from the DB 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.
- write() : void
- Write an entry to the file.
Properties
$compressed
public
bool
$compressed
= true
$excludes
public
array<string|int, string>
$excludes
= []
$log
public
callable|null
$log
= null
$pattern
public
string
$pattern
$rdb
public
Rdb
$rdb
$handle
protected
resource|null
$handle
= null
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'.
export()
Export all data from the DB with the 'pattern' into this file.
public
export(string|resource $file) : int
If providing a file handle, please ensure the type matches the 'compressed' setting. Handles are not closed after writing.
Parameters
- $file : string|resource
Tags
Return values
int —The number of items exported.
isGzip()
Is this file a gzip?
public
static isGzip(string $path) : bool
Parameters
- $path : string
Return values
boolread()
Read all data from the DB with the given 'pattern'.
public
read() : Generator<int, array<string|int, mixed>>
This returns a 1-index key.
Return values
Generator<int, array<string|int, mixed>> —[ key, ttl, 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
boolopen()
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
write()
Write an entry to the file.
protected
write(string $key, int $ttl, string $value) : void
This encodes and zips (if enabled).
Parameters
- $key : string
- $ttl : int
-
milliseconds
- $value : string