2017 © Pedro Peláez
 

library redis-php-stream-wrapper

Implementation of streamWrapper using redis

image

sallyx/redis-php-stream-wrapper

Implementation of streamWrapper using redis

  • Monday, February 19, 2018
  • by sallyx
  • Repository
  • 1 Watchers
  • 4 Stars
  • 32 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 3 % Grown

The README.md

redis-php-stream-wrapper

Build Status Latest Stable Version License, (*1)

This package allows you to register redis server as php stream wrapper, so you will be able to use redis as as stream resource, i.e. 'redis://foo.txt', (*2)

Install

1. Install phpredis/phpredis

See phpredis/phpredis., (*3)

2. Install packages by composer

$ composer require sallyx/redis-php-stream-wrapper

Setup

All together

use Sallyx\StreamWrappers\Redis\ConnectorConfig;
use Sallyx\StreamWrappers\Redis\PathTranslator;
use Sallyx\StreamWrappers\Redis\Connector;
use Sallyx\StreamWrappers\Redis\FileSystem;
use Sallyx\StreamWrappers\Wrapper;

$config = new ConnectorConfig;
$translator = new PathTranslator('www.sallyx.org');
$connector = new Connector($config, $translator);
$fs = new FileSystem($connector);
Wrapper::register($fs);

Step by step

1. Create configuration

use Sallyx\StreamWrappers\Redis\ConnectorConfig;

$config = new ConnectorConfig( // all parameters are optional
    '127.0.0.1',
    $port = 6379,
    $timeout = 0,
    $persistent_id = NULL,
    $retry_interval = NULL
);
$config = new ConnectorConfig('/tmp/redis.sock'); // socket connection

2. Create path translator

use Sallyx\StreamWrappers\Redis\PathTranslator;
$translator = new PathTranslator($prefix = 'www.example.org');

Prefix is used for keys in redis server. For example file 'redis://foo.txt' will be saved in redis under key 'www.example.org://foo.txt'., (*4)

3. Create connector

use Sallyx\StreamWrappers\Redis\Connector;
$connector = new Connector($config, $translator);

4. Create redis file system

use Sallyx\StreamWrappers\Redis\FileSystem;
$fs = new FileSystem($connector);

5. Register as stream wrapper

use Sallyx\StreamWrappers\Wrapper;
Wrapper::register($fs,'redis');

redis is a scheme name of the wrapper ('redis:// ...'), (*5)

6. Profit

mkdir('redis://foo');
file_put_contents('redis://foo/bar.txt', 'hello world');
echo file_get_contents('redis://foo/bar.txt');
...

Using with Nette

If you do not know Nette, have a look at www.nette.org or skip this block :), (*6)

First put setup into app/bootstrap.php or anywhere before you want to use redis stream wrapper. After that you can use redis. For example for temp directory:, (*7)

use Sallyx\StreamWrappers\Redis\Connector;
use Sallyx\StreamWrappers\Redis\ConnectorConfig;
use Sallyx\StreamWrappers\Redis\PathTranslator;
use Sallyx\StreamWrappers\Redis\FileSystem;
use Sallyx\StreamWrappers\Wrapper;

$cc = new ConnectorConfig();
$con = new Connector($cc, new PathTranslator('www.example.org'));
Wrapper::register(new FileSystem($co));
//...
$configurator->enableDebugger('redis://log');
$configurator->setTempDirectory('redis://temp');
//...

Optionally, you can use StreamWrappersExtension in app/config/config.local.neon, which show diagnostic panel in debugger bar., (*8)

extension:
        streamWrappers: Sallyx\Bridges\StreamWrappers\Nette\DI\StreamWrappersExtension

Now you could see your redis filesystem in the panel:, (*9)

diagnostic panel, (*10)

Known issues

If your PHP script ends unexpectedly, all locked files stay locked forever. You can unlock them in redis by this command:, (*11)

HMSET www.example.org://foo/bar.txt lock_ex 0 lock_sh 0

Access rights are not supported (yet?). Functions like chmod(), chgrp(), chown() return always false., (*12)

Calling file_put_contents() with LOCK_EX option triggers E_WARNING "Exclusive locks may only be set for regular files" (This is a PHP bug), (*13)

The Versions

19/02 2018

dev-master

9999999-dev http://github.org/sallyx/redis-php-stream-wrapper

Implementation of streamWrapper using redis

  Sources   Download

BSD-3-Clause GNU 2 GPL-2.0-or-later

The Requires

 

The Development Requires

27/03 2016

v0.9.5

0.9.5.0 http://github.org/sallyx/redis-php-stream-wrapper

Implementation of streamWrapper using redis

  Sources   Download

BSD-3-Clause GNU 2

The Requires

 

The Development Requires

22/11 2015

v0.9.4

0.9.4.0 http://github.org/sallyx/redis-php-stream-wrapper

Implementation of streamWrapper using redis

  Sources   Download

BSD-3-Clause GNU 2

The Requires

 

The Development Requires

09/11 2015

v0.9.3

0.9.3.0 http://github.org/sallyx/redis-php-stream-wrapper

Implementation of streamWrapper using redis

  Sources   Download

BSD-3-Clause GNU 2

The Requires

 

The Development Requires

08/11 2015

v0.9.2

0.9.2.0 http://github.org/sallyx/redis-php-stream-wrapper

Implementation of streamWrapper using redis

  Sources   Download

BSD-3-Clause GNU 2

The Requires

 

The Development Requires

08/11 2015

V0.9.1

0.9.1.0 http://github.org/sallyx/redis-php-stream-wrapper

Implementation of streamWrapper using redis

  Sources   Download

BSD-3-Clause GNU 2

The Requires

 

The Development Requires

05/11 2015

v0.9.0

0.9.0.0 http://github.org/sallyx/redis-php-stream-wrapper

Implementation of streamWrapper using redis

  Sources   Download

BSD-3-Clause GNU 2

The Requires

 

The Development Requires