1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace common\logic\Amqp;
- use Yii;
- /**
- * 缓存设置
- * Class Cache
- * @package common\logic\Amqp
- */
- class Cache
- {
- const CACHE_HEADER = 'message:';
- const STATUS_SEND_FAIL = -1;//发送失败
- const STATUS_SEND_OK = 1;//已发送,待处理
- const STATUS_WAIT = 2;//等待中
- const STATUS_HAND = 3;//处理中
- const STATUS_HAND_OK = 99;//处理成功
- const STATUS_HAND_FAIL = -99;//处理失败
- public static $statusMark = [
- -1 => '发送失败',
- 0 => '未知状态',
- 1 => '已发送,待处理',
- 2 => '等待中',
- 3 => '处理中',
- 99 => '处理成功',
- -99 => '处理失败',
- ];
- /**
- * [设置缓存状态]
- * @author: libingke
- * @param $key
- * @param $value
- * @param bool $time
- * @return bool
- */
- public static function setData($key, $value, $time = false)
- {
- $cache = Yii::$app->redis;
- if ($key) {
- if (is_numeric($time)) {
- return $cache->set(static::CACHE_HEADER . $key, $value, $time);
- }
- return $cache->set(static::CACHE_HEADER . $key, $value);
- }
- return false;
- }
- /**
- * [获取缓存状态]
- * @author: libingke
- * @param $key
- * @return bool
- */
- public static function getData($key)
- {
- $cache = Yii::$app->redis;
- return $cache->get(static::CACHE_HEADER . $key);
- }
- /**
- * [删除缓存状态]
- * @author: libingke
- * @param $key
- * @return mixed
- */
- public static function deleteData($key)
- {
- $cache = Yii::$app->redis;
- return $cache->delete(static::CACHE_HEADER . $key);
- }
- /**
- * [查询状态]
- * @author: libingke
- * @param $id
- * @return mixed|null
- */
- public static function getMarkById($id)
- {
- if (isset(self::$statusMark[$id]) && is_numeric($id)) {
- return self::$statusMark[$id];
- }
- return self::$statusMark[0];
- }
- }
|