2017 © Pedro Peláez
 

library predis-commands

Adds some useful commands to Predis.

image

angyvolin/predis-commands

Adds some useful commands to Predis.

  • Monday, May 1, 2017
  • by angyvolin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3,186 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 5 % Grown

The README.md

predis-commands

Adds some [Lua][4]-based atomic commands to Predis., (*1)

Motivation

Any individual Redis command is always atomic because Redis is single threaded. In some cases you may want to run several Redis commands atomically., (*2)

There are two common ways to achieve this: - Redis transactions. It utilizes MULTI/EXEC Redis commands to run some commands in sequence It also uses WATCH/DISCARD Redis commands for CAS optimistic concurrency. - Redis scripts. This one is transactional by definition: Redis uses the same Lua interpreter to run all the commands and guarantees that no other script or Redis command will be executed while a script is being executed., (*3)

This project uses Lua Scripting approach as it's usually both simpler and faster., (*4)

Installation

composer require angyvolin/predis-commands

What's included?

As of now, the predis-commands project extends Predis with following commands:, (*5)

ZPOP - Removes and returns the top value in a zset, with its score.
ZRPOP - Removes and returns the bottom value in a zset, with its score.

How to use predis-commands ...

... in plain PHP

Code snippet below demonstrates how to use predis-commands regardless of any framework, (*6)

<?php

require __DIR__.'/../vendor/autoload.php';

use Angyvolin\Predis\Command;

$client = new Predis\Client();
$client->getProfile()->defineCommand('zpop', Command\ZSetPop::class);
$client->getProfile()->defineCommand('zrpop', Command\ZSetReversePop::class);

... in Silex application

Code snippet below demonstrates integration with Silex application, (*7)

<?php

use Pimple\Container;
use Pimple\ServiceProviderInterface;
use Angyvolin\Predis\Command;

class PredisCommandsServiceProvider implements ServiceProviderInterface
{
    public function register(Container $app)
    {
        $app->extend('redis', function ($redis) {
            /* @var \Predis\Client $redis */
            $redis->getProfile()->defineCommand('zpop', Command\ZSetPop::class);
            $redis->getProfile()->defineCommand('zrpop', Command\ZSetReversePop::class);

            return $redis;
        });
    }
}

Tests:

Tu run tests execute following command in a root directory of the predis-commands project:, (*8)

phpunit

License

MIT License, (*9)

The Versions

01/05 2017

dev-master

9999999-dev

Adds some useful commands to Predis.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andrii Volin

01/05 2017

0.1.3

0.1.3.0

Adds some useful commands to Predis.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andrii Volin

01/05 2017

0.1.2

0.1.2.0

Adds some useful commands to Predis.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andrii Volin

30/04 2017

0.1.1

0.1.1.0

Adds some useful commands to Predis.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andrii Volin

30/04 2017

0.1.0

0.1.0.0

Adds some useful commands to Predis.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Andrii Volin