Giter Club home page Giter Club logo

redis's Introduction

component used to access Redis

install

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

feature

Fire event on each redis command when an eventDispatcher is setted.

$this->setEventDispatcher($eventDispatcher, $eventClass);

cache mode

M6Web\Component\Redis\Cache

Send redis command to different server with a simple consistent hashing algorithm. Ignore server not responding.

When a redis server fall, keys are dispatched on the other servers.

$server_config = array(
        'php50' => array (
            'ip' => '127.0.0.1',
            'port' => 6379,
            ),
'phpraoul' => array (  // bad server
    'ip' => '1.2.3.4',
    'port' => 6379,
    ),
'php51' => array (
    'ip' => '127.0.0.1',
    'port' => 6379,
    )
);
$redis = new redis\Cache(array(
    'timeout' => self::TIMEOUT,
    'server_config' => $server_config,
    'namespace' => self::SPACENAME
    ));
$redis->set('foo', 'bar');
$foo = $redis->get('foo');
if ($redis->exists('raoul')) die('ho mon dieu il existe vraiment !');
$redis->multi()->set('foo', 'bar2');
$redis->watch('raoul');
$raoul = UnClasse::WorkHard();
$redis->set('raoul', $raoul); // wont do anything if the raoul key is modified
$redis->exec(); // execute all sets since the multi instructions
$redis->incr('compteur');
$redis-decr('compteur');

Check unit test for more informations.

db mode

M6Web\Component\Redis\DB

Access to the predis object simply calling the predis methods.

Multi mode

M6Web\Component\Redis\Multi

Send redis command to multiple server or send command to a random redis server.

$server_config = array(
        'php50' => array (
            'ip' => 'x.x.x.1',
            'port' => 6379,
            ),
        'php51' => array (
            'ip' => 'x.x.x.2',
            'port' => 6379,
            ),
);
$redis = new redis\Multi(['timeout' => 0.1,
                         'server_config' => $server_config]);

try{
    $redis->onAllServer($strict = true)->set('foo', 'bar');
} catch(redis\Exception $e) {
    die('error occured on setting foo bar on a server');
}
// strict mode disabled, don't care about server availability
$redis->onAllServer($strict = false)->set('foo', 'bar');

// read value on a random server
try {
    $value = $redis->onOneRandomServer()->get('foo');
} catch(redis\Exception $e) {
    die('no server available');
}

timeouts

A connection timeout is availaible through the timeout parameter. A read write timeout can be specified with the read_write_timeout parameter (by default, equal to the connection timeout).

$redis = new redis\Cache(array(
    'timeout' => 0.5,
    'read_write_timeout' => 0.2,
    'server_config' => $server_config,
    'namespace' => self::SPACENAME
    ),
);

tests

./vendor/bin/atoum -d tests

Unfortunatly you need redis setuped on localhost for all the tests working.

TODO

  • use SPLQueue
  • refactor unit tests

redis's People

Contributors

fabdsp avatar jdlabails avatar jdohuutin avatar lnahiro avatar mojolyon avatar omansour avatar remilemonnier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

redis's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.