swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 786 forks source link

redis在worker和task进程的返回格式有区别,建议统一 #169

Closed CoderPoet closed 6 years ago

CoderPoet commented 6 years ago
Q A
Bug report? no
Feature request? yes
Swoft version 1.0.0
Swoole version 2.1.2
PHP version 7.2.2
Runtime environment Mac

Details

Describe what you are trying to achieve and what goes wrong.

//  worker进程 redis返回的是一个索引数组
array(6) {
  [0]=>
  string(3) "108"
  [1]=>
  string(1) "2"
  [2]=>
  string(10) "1522058400"
  [3]=>
  string(10) "1522062000"
  [4]=>
  string(10) "1522058161"
  [5]=>
  string(10) "1522058161"
}

// task进程返回的是一个关联数组
array(6) {
  ["id"]=>
  string(3) "108"
  ["status"]=>
  string(1) "3"
  ["startTime"]=>
  string(10) "1522058400"
  ["endTime"]=>
  string(10) "1522062000"
  ["createdAt"]=>
  string(10) "1522058161"
  ["updatedAt"]=>
  string(10) "1522058161"
}

// 二者不统一,业务逻辑中需要判断处理,比较麻烦。建议统一一下

Provide minimal script to reproduce the issue

// worker和task进程的返回格式有区别
$this->redis->hMGet(ActivityConstants::NOW_ACTIVITY, $keys);
stelin commented 6 years ago

我们统一下,因为协程环境使用的是协程客户端,task环境,使用的是传统的同步IO阻塞操作

CoderPoet commented 6 years ago

@stelin 另外 task进程下的同步redis客户端 不能自动反序列化,这个最好也统一做成能够反序列化的,不然的话需要区别处理了

stelin commented 6 years ago

应该是支持的,通过配置是否序列化

huangzhhui commented 6 years ago

https://github.com/swoft-cloud/swoft-component/pull/142