response->result)) && ($obj->response->result) && (isset($obj->response->resultcount)) && ($obj->response->resultcount == 1)) { $workshopData = $obj->response->publishedfiledetails[0]; // Store data in cache self::setToCache($cacheKey, json_encode($workshopData)); return $workshopData; } throw new \Exception('Invalid data response'); } /** * Get data from Redis cache * * @param $key * @return mixed|bool */ private static function getFromCache($key) { $redis = new Redis(); $redis->connect(env('REDIS_HOST'), env('REDIS_PORT')); if (env('REDIS_PASS') !== '') { $redis->auth(env('REDIS_PASS')); } $redis->select(env('REDIS_DATABASE')); // Selecting Redis database index $cachedData = $redis->get($key); if ($cachedData !== false) { return json_decode($cachedData); } return false; } /** * Set data to Redis cache * * @param $key * @param $value */ private static function setToCache($key, $value) { $redis = new Redis(); $redis->connect(env('REDIS_HOST'), env('REDIS_PORT')); if (env('REDIS_PASS') !== '') { $redis->auth(env('REDIS_PASS')); } $redis->select(env('REDIS_DATABASE')); // Selecting Redis database index $redis->set($key, json_encode($value), env('REDIS_EXPIRATION')); } }