public function all($limit = 10) { if (!($tagKeys = Redis::keys("tags:{$this->language}:*"))) { $posts = $this->loader->loadList(); foreach ($posts as $item) { $post = $this->loader->load($item['slug'], $item); foreach ($post['tags'] as $tag) { if (Redis::sadd(Key::tags($tag), $item['slug']) && !in_array(Key::tags($tag), $tagKeys)) { $tagKeys[] = Key::tags($tag); } } } } $tags = []; foreach ($tagKeys as $key) { $chunks = explode(':', $key); $key = array_pop($chunks); $tags[$key] = Redis::scard(Key::tags($key)); } arsort($tags); return array_slice($tags, 0, $limit); }