123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace components\service;
- use Yii;
- class Redis
- {
- const KEYS_STATUS = 'statistic:status';
- const TYPE_STATUS = 'status';
- const TYPE_RESULT = 'result';
-
- public static function set($queue, $mid, $type, $val)
- {
- $key = static::getKey($queue, $mid, $type);
- if ($type == static::TYPE_STATUS)
- Yii::$app->redis->hmset(static::KEYS_STATUS, $mid, $val);
- return Yii::$app->redis->set($key, $val);
- }
-
- public static function getStatusList()
- {
- return Yii::$app->redis->hgetall(static::KEYS_STATUS);
- }
-
- public static function get($queue, $mid, $type)
- {
- $key = static::getKey($queue, $mid, $type);
- return Yii::$app->redis->get($key);
- }
-
- public static function del($queue, $mid, $type)
- {
- $key = static::getKey($queue, $mid, $type);
- return Yii::$app->redis->del($key);
- }
-
- public static function expire($queue, $mid, $type, $expiration = 86400 * 7)
- {
- $key = static::getKey($queue, $mid, $type);
- return Yii::$app->redis->expire($key, $expiration);
- }
-
- public static function getKey($queue, $mid, $type)
- {
- if ( $queue && $mid && in_array($type, [static::TYPE_STATUS, static::TYPE_RESULT]) )
- return "queue:$queue:$mid:$type";
- throw new \Exception("参数设置错误");
- }
-
- public static function purge($queue)
- {
- }
-
- public static function batchDel($queue, $delete, $type)
- {
- }
- }
|