为什么 php memcached 层没有按预期散列我的密钥?

Why php memcached layer is not hashing my key as expected?

我正在使用 php5-memcached(libmemcached 版本:1.0.8)

阅读此手册页后
http://php.net/manual/en/memcached.constants.php

我知道在 get and set 方法中传递的键在与 memcached 通信时被散列,并且默认 hasing 算法是 "Jenkins has function"

Memcached::OPT_HASH
Specifies the hashing algorithm used for the item keys. The valid values are supplied via Memcached::HASH_* constants. Each hash algorithm has its advantages and its disadvantages. Go with the default if you don't know or don't care.

Type: integer, default: Memcached::HASH_DEFAULT

Memcached::HASH_DEFAULT
The default (Jenkins one-at-a-time) item key hashing algorithm.

但是当我尝试使用具有无效 memcached 字符(例如 space 字符)的密钥时,似乎没有创建 memcached 项目。

可以肯定的是,我

service memcached restart

然后我设置我的缓存项

$m = new Memcached();
$m->addServer('localhost', 11211);
$m->set("pesce azzurro", "ciao!", time() + 14400)
var_dump($m->getResultCode());

操作失败,错误 9 应该是

09 = MEMCACHED_CLIENT_ERROR

我试试看

 echo "stats items" | nc localhost 11211

并且输出显示没有项目

END

所以我的问题是,为什么 php memcached 层没有按预期获得我的密钥?
我应该外部散列我的密钥宽度 md5 吗?

密钥本身未经过哈希处理,因此您仍然必须使用有效的密钥名称。

密钥的散列版本用于确定密钥应存储在集群中的哪个服务器上/从中检索。如果您有两台服务器,MD5 哈希从 0-7 开始的密钥可能会在服务器 1 上结束,而哈希从 8-f 开始的密钥可能会在服务器 2 上结束,但是这些服务器将存储未散列密钥本身下的数据.