incr('ACID'); if (!$newCustomId) { $strErr = '客服消息自增ID获取失败!'; Log::error($strErr); throw new HttpException(500, $strErr); } return $newCustomId; } /** * 获取模板消息自增id * @return int */ public function getTemplateMessageId() { $redisAuto = Redis::instanceAuto(); $newTemplateMessageId = $redisAuto->incr('TMID'); if (!$newTemplateMessageId) { $strErr = '模板消息自增ID获取失败'; Log::error($strErr); throw new HttpException(500, $strErr); } return $newTemplateMessageId; } /** * 获取推广链接自增id * @return int */ public function getAutoReferralId() { $redisAuto = Redis::instanceAuto(); $newReferralId = $redisAuto->incr('RFID'); if (!$newReferralId) { $strErr = '推广链接自增ID获取失败!'; Log::error($strErr); throw new HttpException(500, $strErr); } return $newReferralId; } /** * 获取短链接自增id * @return int */ public function getAutoShortUrlId() { $redisAuto = Redis::instanceAuto(); $newShortUrlId = $redisAuto->incr('SUID'); if (!$newShortUrlId) { $strErr = '短链接自增ID获取失败!'; Log::error($strErr); throw new HttpException(500, $strErr); } return $newShortUrlId; } #region 短链接 /** * 获取短链接redis-key * @param $id * @return string */ private function _getShortUrlKey($id) { return self::REDIS_KEY_SHORT_URL . $id; } /** * 从redis获取短链接 * @param $id * @return bool|string */ public function getShortUrl($id) { $redis = Redis::instance(); $key = $this->_getShortUrlKey($id); return $redis->get($key); } /** * 设置redis短链接 * @param $id * @param $url * @return bool * @throws \Exception */ public function setShortUrl($id, $url) { $redis = Redis::instance(); $key = $this->_getShortUrlKey($id); $result = $redis->set($key, $url, 3600); if (!$result) { throw new \Exception('设置短连接redis失败'); } return $result; } #endregion }