redis - "Warning: Memcached::setOption() expects parameter 1 to be integer, string given"使用来自 "Redis Enterprise Cloud"的 Redis Memcached 和 Symfony 5

标签 redis memcached php-7 symfony5

以下是我的 Symfony 项目的 services.yaml 的配置,
[我正在尝试在 Redis Enterprise Cloud Memcached 上存储 session ]

parameters:
   session_memcached_host: memcached-11999.someurl.redislabs.com
   session_memcached_port: 11999
   session_memcached_prefix: test
   session_memcached_expire: 3600 # this is in seconds
   session_memcached_user: abcd
   session_memcached_pass: abcd

services:
    session.memcached:
        class: Memcached
        arguments:
        calls:
           - [addServer, ['%session_memcached_host%','%session_memcached_port%']]
#           - [setSaslAuthData, ['%session_memcached_user%','%session_memcached_pass%']]
           - [setOption, [Memcached::OPT_BINARY_PROTOCOL, true]]

    session.handler.memcached:
        class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler
        arguments: ["@session.memcached", { prefix: '%session_memcached_prefix%', expiretime: '%session_memcached_expire%' }]


出现以下错误异常
in var/cache/dev/ContainerIG8bgiG/App_KernelDevDebugContainer.php (line 1635)

include_once \dirname(__DIR__, 4).'/vendor/symfony/http-foundation/Session/SessionBagInterface.php';
include_once \dirname(__DIR__, 4).'/vendor/symfony/http-foundation/Session/Storage/MetadataBag.php';        
$a = new \Memcached();       
$a->addServer('memcached-11999.someurl.redislabs.com', 11999);        
$a->setOption('Memcached::OPT_BINARY_PROTOCOL', true);        
return $this->privates['session.storage.native'] = new\Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage($this->parameters['session.storage.options'], new \Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler($a, ['prefix' => 'test', 'expiretime' => 3600]), new \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag('_sf2_meta', 0));    }    /**


如果我取消注释以下行
- [setSaslAuthData, ['%session_memcached_user%','%session_memcached_pass%']]

然后它给出以下警告,因为它不支持没有二进制文件的 SASL
Warning: Memcached::setSaslAuthData(): SASL is only supported with binary protocol


出现以下错误异常
in var/cache/dev/ContainerNVvLqte/App_KernelDevDebugContainer.php (line 1635)

include_once \dirname(__DIR__, 4).'/vendor/symfony/http-foundation/Session/SessionBagInterface.php';        
include_once \dirname(__DIR__, 4).'/vendor/symfony/http-foundation/Session/Storage/MetadataBag.php';
$a = new \Memcached();
$a->addServer('memcached-11999.someurl.redislabs.com', 11999);
$a->setSaslAuthData('abcd', 'abcd');        
$a->setOption('Memcached::OPT_BINARY_PROTOCOL', true);        

return $this->privates['session.storage.native'] = new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage($this->parameters['session.storage.options'], new \Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler($a, ['prefix' => 'test', 'expiretime' => 3600]), 
new \Symfony\Component\HttpFoundation\Session\Storage\MetadataBag('_sf2_meta', 0));    }

最佳答案

我不明白为什么 Symfony 仅在将第一个参数 'Memcached::OPT_BINARY_PROTOCOL' 添加到 services.yaml 时才将其视为字符串!

我通过启用默认 memcached.default_binary_protocol 解决了这个问题

我在/etc/php/7.2/mods-available/memcached.ini 中添加了这一行

memcached.default_binary_protocol = On

Check this screen shot of info.php

以下是我对 Symfony 项目的 services.yaml 文件的最终配置
parameters:
   session_memcached_host: memcached-11999.someurl.redislabs.com
   session_memcached_port: 11999
   session_memcached_prefix: test
   session_memcached_expire: 3600 # this is in seconds
   session_memcached_user: abcd
   session_memcached_pass: abcd

services:
    session.memcached:
        class: Memcached
        arguments:
        calls:
           - [setSaslAuthData, ['%session_memcached_user%','%session_memcached_$
           - [addServer, ['%session_memcached_host%','%session_memcached_port%'$

    session.handler.memcached:
        class: Symfony\Component\HttpFoundation\Session\Storage\Handler\Memcach$
        arguments: ["@session.memcached", { prefix: '%session_memcached_prefix%$


现在它在 Redislabs Memcached 上存储 session :)

关于redis - "Warning: Memcached::setOption() expects parameter 1 to be integer, string given"使用来自 "Redis Enterprise Cloud"的 Redis Memcached 和 Symfony 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59250506/

相关文章:

c# - 如何将Redis Value []转换为反序列化对象C#?

redis - 本地redis数据库(db)在哪里?

ruby-on-rails - 如何在 Rails 中缓存哈希值?

php - 加速 jQuery AutoComplete(不可避免的长列表)

php-7 - PHP7 : Unknown hashing algorithm: sha256

mongodb - 哪个 nosql 选项相对于存储过程和大型数组?

Redis主从同步死循环

python - Redis 或 Memcached 是否可以用于 "lock"资源,例如 S3 之类的 blobstore?

php - ssh2 上的 opendir 永远不会停止

php - 在php7中读取POST数据