【发布时间】:2016-08-18 01:51:52
【问题描述】:
我在我的网站 (Laravel 4.2) 中使用 Redis 作为会话存储。有时我会遇到以下错误。我猜 ">" char 破坏了 setex 命令。
production.ERROR: exception 'Predis\ServerException' with message 'ERR unknown command '>'' in
production.ERROR: exception 'Predis\ServerException' with message 'ERR unknown command 'tml>''
production.ERROR: exception 'Predis\ServerException' with message 'ERR unknown command '</div>''
这些错误在生产服务器上很少发生,我无法重现它们。您知道为什么会发生这些错误以及如何防止它们吗?
key: laravel:xxxxxxxxxxxxxxx
value: s:217:"a:4:{s:6:"_token";s:40:"xxxxxxxxxxx";s:4:"lang";s:2:"fr";s:9:"_sf2_meta";a:3:{s:1:"u";i:1461777248;s:1:"c";i:1461777248;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}";
exception 'Predis\ServerException' with message 'ERR unknown command 'ml>'' in vendor/predis/predis/lib/Predis/Client.php:282
更新
我使用 redis 的代码示例。
public function view($username = null)
{
$username = mb_strtolower($username);
$redis = $this->getRedis();
try{
$view = $redis->get(User::getCacheKeyByUsername($username));
}catch (\Exception $exception){
$view = null;
}
if($view === null || Session::has("admin")){
$user = User::where('username', '=', $username)->where("status", 1)->first();
if (empty($user)) {
return Redirect::to(Session::get("lang") . '/all');
}
$view = View::make("view", array("user" => $user));
if(!Session::has("admin")){
try{
$redis->setex(User::getCacheKeyByUsername($username), 3600, $view);
}catch (\Exception $exception){
Log::error($exception->getMessage());
}
}
}
return $view;
}
【问题讨论】:
-
错误的字符串插值?
-
@Ferid Movsumov,这个问题解决了吗?
-
@mnv 不幸的是问题仍然存在。
-
我今天遇到了同样的问题。也许你的情况也是如此:github.com/nrk/predis/issues/328
-
@FeridMovsumov 明白了。也许解决方法是将特殊字符转换为 html 实体,然后在检索它时进行反向处理?我说的是
htmlspecialchars和htmlspecialchars_decode
标签: php laravel laravel-4 redis predis