8000 [Cache][Lock] Add RedisProxy for lazy Redis connections by nicolas-grekas · Pull Request #24887 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache][Lock] Add RedisProxy for lazy Redis connections #24887

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

Merged
merged 1 commit into from
Nov 10, 2017

Conversation

nicolas-grekas
Copy link
Member
@nicolas-grekas nicolas-grekas commented Nov 9, 2017
Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #24865
License MIT
Doc PR -

That's the only provider that is not lazy by default, leading to bad DX (see linked issue.)
Best reviewed ignoring whitespaces.

@nicolas-grekas
Copy link
Member Author

(now investigating the failure)

@nicolas-grekas
Copy link
Member Author

PR ready.

@jderusse
Copy link
Member

Same issue affects the Lock component, and could be patched in the same way. I will open a PR when this one will be merged to reuse the RedisProxy. (thanks FWBundle has a dependency on Cache)

Diff is to take into account and allow the new class RedisProxy in Symfony\Component\Lock\Store\RedisStore and in Symfony\Component\Lock\Store\StoreFactory and add the array('lazy' => true) in the FrameworkExtension

@nicolas-grekas nicolas-grekas changed the title [Cache] Add RedisProxy for lazy Redis connections [Cache][Lock] Add RedisProxy for lazy Redis connections Nov 10, 2017
@@ -49,7 +50,7 @@ public function init($redisClient, $namespace = '', $defaultLifetime = 0)
}
if ($redisClient instanceof \RedisCluster) {
$this->enableVersioning();
} elseif (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \Predis\Client) {
} elseif (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \Predis\Client && !$redisClient instanceof RedisProxy) {
throw new InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\Client, %s given', __METHOD__, is_object($redisClient) ? get_class($redisClient) : gettype($redisClient)));
Copy link
Contributor

Choose a reason for hiding this comment

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

this message needs an update right? Same for below.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer not: RedisProxy is internal (same for docblocks)

Copy link
Contributor

Choose a reason for hiding this comment

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

right! 👍

@fabpot
Copy link
Member
fabpot commented Nov 10, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 1f5e353 into symfony:3.4 Nov 10, 2017
fabpot added a commit that referenced this pull request Nov 10, 2017
…s (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[Cache][Lock] Add RedisProxy for lazy Redis connections

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24865
| License       | MIT
| Doc PR        | -

That's the only provider that is not lazy by default, leading to bad DX (see linked issue.)
Best reviewed [ignoring whitespaces](https://github.com/symfony/symfony/pull/24887/files?w=1).

Commits
-------

1f5e353 [Cache][Lock] Add RedisProxy for lazy Redis connections
@nicolas-grekas nicolas-grekas deleted the lazy-redis branch November 10, 2017 15:26
This was referenced Nov 12, 2017
@ahilles107
Copy link
ahilles107 commented Nov 20, 2017

Hey, looks like it breaks Memcached adapter.


constant(): Couldn't find constant Memcached::OPT_LAZY
--
in MemcachedTrait.php (line 148)
at MemcachedAdapter::Symfony\Component\Cache\Traits\{closure}(2,  'constant(): Couldn\'t find constant Memcached::OPT_LAZY',  '/Users/pawelmikolajczuk/Projects/asystentciazy-server/vendor/symfony/cache/Traits/MemcachedTrait.php',  148, array('servers' => array(array('127.0.0.1', 11211, 0)), 'options' => array('LAZY' => true, 'SERIALIZER' => 'php'), 'client' => object(Memcached), 'username' => null, 'password' => null, 'dsn' => 'memcached://127.0.0.1:11211', 'i' => 0, 'params' => array('scheme' => 'file', 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 0), 'value' => true, 'name' => 'LAZY'))
at constant('Memcached::OPT_LAZY')in MemcachedTrait.php (line 148)
at MemcachedAdapter::createConnection(array(array('127.0.0.1', 11211, 0)), array('LAZY' => true, 'SERIALIZER' => 'php'))in AbstractAdapter.php (line 134)
at AbstractAdapter::createConnection('memcached://127.0.0.1:11211', array('lazy' => true))in AppDevDebugProjectContainer.php (line 2444)
doctrine:
    orm:
        ...
        metadata_cache_driver:
            type: service
            id: doctrine.system_cache_provider
        query_cache_driver:
            type: service
            id: doctrine.system_cache_provider
        result_cache_driver:
            type: service
            id: doctrine.result_cache_provider

services:
    doctrine.result_cache_provider:
        class: Symfony\Component\Cache\DoctrineProvider
        public: false
        arguments:
            - '@doctrine.result_cache_pool'
    doctrine.system_cache_provider:
        class: Symfony\Component\Cache\DoctrineProvider
        public: false
        arguments:
            - '@doctrine.system_cache_pool'

framework:
    cache:
        default_memcached_provider: "memcached://127.0.0.1:11211"
        pools:
            doctrine.result_cache_pool:
                adapter: cache.app
            doctrine.system_cache_pool:
                adapter: cache.adapter.memcached
                public: true

@nicolas-grekas
Copy link
Member Author

@ahilles107 correct, see #25038. I invite you to create issues when encountering an issue, as comments on closed PRs/issues are kinda lost most of the time. And looking at the history before doing so ;)

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

Successfully merging this pull request may close these issues.

7 participants
0