问题
无论有没有账号密码,连接方式不都应该是统一的吗?
在查看 Yii2 的 Memcached 驱动文件时,发现在有账号密码的情况下,进行二进制连接,否则进行的是简单连接。
相关
Yii2 版本:2.0.13
位置:vendor/yiisoft/yii2/caching/MemCache.php:225
if ($this->useMemcached) {
$this->_cache = $this->persistentId !== null ? new \Memcached($this->persistentId) : new \Memcached();
if ($this->username !== null || $this->password !== null) {
$this->_cache->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
$this->_cache->setSaslAuthData($this->username, $this->password);
}
因为Memcached二进制协议才支持SASL。
所以这里的逻辑是,你要用密码和账号,所以要开二进制协议。