Skip to content

[5.4] Make PhpRedis connection more compatible with Predis (pipeline, ...) - #18421

Merged
taylorotwell merged 3 commits into
laravel:5.4from
alibo:phpredis-compatibility
Mar 19, 2017
Merged

[5.4] Make PhpRedis connection more compatible with Predis (pipeline, ...)#18421
taylorotwell merged 3 commits into
laravel:5.4from
alibo:phpredis-compatibility

Conversation

@alibo

@alibo alibo commented Mar 19, 2017

Copy link
Copy Markdown
Contributor

This PR makes PhpRedis connection more compatible with Predis. It allows you to use closure for pipeline or transaction. Also for raw commands, it adds executeRaw, same as Predis library.

1. Pipeline:

$result = Redis::pipeline(function ($pipe) {
   $pipe->set('test:pipeline:1', 1);
   $pipe->get('test:pipeline:1');
   $pipe->set('test:pipeline:2', 2);
   $pipe->get('test:pipeline:2');
});

dump($result);
array:4 [
  0 => true
  1 => "1"
  2 => true
  3 => "2"
]

PhpRedis docs: https://github.com/phpredis/phpredis#multi-exec-discard
Predis docs: https://github.com/nrk/predis#command-pipelines

2. Transaction:

$result = Redis::transaction(function ($pipe) {
   $pipe->set('test:transaction:1', 1);
   $pipe->get('test:transaction:1');
   $pipe->set('test:transaction:2', 2);
   $pipe->get('test:transaction:2');
});

dump($result);
array:4 [
  0 => true
  1 => "1"
  2 => true
  3 => "2"
]

PhpRedis docs: https://github.com/phpredis/phpredis#multi-exec-discard
Predis docs: https://github.com/nrk/predis#transactions

3. Raw Commands

Predis Style:

Redis::set('test:raw', 1);
Redis::executeRaw(['GET', 'test:raw']);

PhpRedis Style:

Redis::set('test:raw', 1);
Redis::rawCommand('GET', 'test:raw');

PhpRedis docs: https://github.com/phpredis/phpredis#rawcommand
Predis docs: https://github.com/nrk/predis#adding-new-commands


Also I added 3 tests for these methods.

@alibo alibo changed the title [5.4] Make PhpRedis connection more compatible with Predis (pipeline, ...) [WIP] [5.4] Make PhpRedis connection more compatible with Predis (pipeline, ...) Mar 19, 2017
@alibo

alibo commented Mar 19, 2017

Copy link
Copy Markdown
Contributor Author

It looks like the old version of phpredis doesn't have rawCommand method. I'm working on it...

@alibo

alibo commented Mar 19, 2017

Copy link
Copy Markdown
Contributor Author

The method rawCommand has been implemented in version 2.2.7 on Jan 18, 2015 (2 years ago!).
The preinstalled Redis extension for PHP 5.6 in Travis CI is very old.

I changed travis.yml and now it installs the latest version with pecl. If you think it may break something, I can remove method executeRaw. What do you think?

@alibo alibo changed the title [WIP] [5.4] Make PhpRedis connection more compatible with Predis (pipeline, ...) [5.4] Make PhpRedis connection more compatible with Predis (pipeline, ...) Mar 19, 2017
@taylorotwell
taylorotwell merged commit d06930d into laravel:5.4 Mar 19, 2017
Comment thread .travis.yml
- if [[ $TRAVIS_PHP_VERSION != 7.1 ]] ; then phpenv config-rm xdebug.ini; fi
- echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- pecl install -f redis

@lucasmichot lucasmichot Mar 19, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you reinstall Redis extension?
It is already installed: https://docs.travis-ci.com/user/languages/php#PHP-7.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucasmichot you're right, but the problem is the installed version. for PHP 7 and 7.1, it's ok, but for PHP 5.6, it has an old version of phpredis extension (< 2.2.7).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants