hMGet($key, self::getHashKeyList()); foreach ($result as $k => $v) { $result[$k] = intval($v); } } catch (\Exception $ex) { $result = null; } return $result; } /** * @param $id * @param $hashKey * @param int $value * @return bool */ public static function hSet($id, $hashKey, $value) { $key = self::getKey($id); try { $result = self::getConnection(true)->hSet($key, $hashKey, $value); } catch (\Exception $ex) { $result = false; } return $result; } /** * 加1 * @param $id * @param $hashKey * @param int $value 负数时减少 * @return int */ public static function hIncrBy($id, $hashKey, $value = 1) { $key = self::getKey($id); try { $result = self::getConnection(true)->hIncrBy($key, $hashKey, $value); } catch (\Exception $ex) { $result = false; } return $result; } /** * 删除 * @param $id * @return bool */ public static function delete($id) { $key = self::getKey($id); try { $result = self::getConnection(true)->delete($key); } catch (\Exception $ex) { $result = false; } return $result; } /** * 设置过期时间 * @param $id * @param $expire * @return mixed */ public static function setExpire($id, $expire = null) { if (is_null($expire)) { $class = get_called_class(); $expire = $class::EXPIRE; } else { $expire = intval($expire); } $key = self::getKey($id); try { $result = self::getConnection(true)->expire($key, $expire); } catch (\Exception $ex) { $result = false; } return $result; } /** * 获取hashKey列表 * @return mixed */ protected static function getHashKeyList() { $class = get_called_class(); $hashKeyList = $class::$hashKeyList; return $hashKeyList; } /** * 获取连接池 * @param bool $isMaster * @return \Redis */ protected static function getConnection($isMaster = false) { $class = get_called_class(); $configClass = $class::CONFIG_CLASS; $redis = new \PhpLife\Frame\Library\Redis($configClass); $connection = $redis->getConnection($isMaster); return $connection; } }