【发布时间】:2020-04-07 08:34:41
【问题描述】:
我有这个功能:
public function showProfile($id)
{
// Check if user already in redis with cache key user.1 for example
if (!Redis::exists('user.' . $id)) {
// If the user is not in redis, fetch it from DB and add it in redis for 60 seconds before returning it
$user = User::findOrFail($id);
Redis::set('user.' . $user->id, $user);
return $user;
} else {
// If user is in redis, just return it without querying the database
return Redis::get('user'.$id);// How to set this?
}
但是函数返回为null,请问为什么...
【问题讨论】:
-
你有什么理由想直接使用redis而不是cache和redis驱动?
-
就像 Remul 说的,直接使用 Redis 没有意义。将缓存与 redis 驱动程序一起使用。如果您已经在不同的驱动程序上拥有缓存并且只想为此目的使用 Redis,那么只需将缓存与多个驱动程序一起使用。