set(self::lastSeenKey($userId), ($seenAt ?? Carbon::now())->toISOString()); } public static function getLastSeen(int $userId): ?Carbon { $lastSeen = Redis::connection()->get(self::lastSeenKey($userId)); return $lastSeen ? Carbon::parse($lastSeen) : null; } private static function lastSeenKey(int $userId): string { return sprintf('last_seen:%d', $userId); } }