在Redis中设置布尔值会导致PHP中出现502错误

时间:2018-10-30 11:12:34

标签: php redis

为什么PHP代码可以

$redis = new Redis();
$redis->connect('127.0.0.1', '6379');
$redis->set("testkeybool", false);

导致502错误?

2018/10/30 13:59:29 [error] 23512#0: *12 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: ..., server: my.host, request: "GET /test.php HTTP/1.0", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "..."

如果我设置boolean的整数instad,就可以了

$redis->set("testkeybool", 0);

nginx配置

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

PHP版本PHP 5.6.36

1 个答案:

答案 0 :(得分:0)

这是因为redis仅支持以下数据类型string, list, hash, set, sorted set, bitmaps, and hyperlogs。使用setter $redis->set();(使用Set键保存字符串值)时,它必须采用其中一种数据类型的形式

尝试

$redis = new Redis();
$redis->connect('127.0.0.1', '6379');
$redis->set('testkeybool', 'false');