Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 19, 2017

Conversation

alibo
Copy link
Contributor

@alibo alibo commented Mar 19, 2017

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
Copy link
Contributor Author

alibo commented Mar 19, 2017

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

@alibo
Copy link
Contributor Author

alibo commented Mar 19, 2017

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
@@ -30,7 +30,7 @@ services:
before_install:
- 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
Copy link
Contributor

@lucasmichot lucasmichot Mar 19, 2017

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
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