Closed ttodua closed 3 years ago
Dear Swoole team, please make this enhancement:
If my understanding is correct, after updating value (with ->set()
function), then ->put($redis)
is needed to put the updated redis instance back to pool. However, it would be nice that it was not needed to manually call ..->put($redis);
in the end of every go
function. It's just inconvenient.
Please make an overload of ->set()
command (i.e. third flag, set to true
like):
$redis->set ('key', 'value', true);
So, the set
function (inside itself) will do ->put($redis)
after updating the key&value, so we wont be required to call ->put($redis)
manually in the end of every go
function.
In higher versions, when you use Coroutine\run
, all HOOKs are enabled by default, so there is no need for Runtime::enableCoroutine
.
@sy-records Ok thanks for answering (your answer can be included in DOCs too) the question #2, but could you tell several words bout q1 ?
If a connection object becomes unusable, the developer needs to call $pool->put(null);
to return an empty connection to keep the connection pool balanced.
So we keep it and let the developers handle it. You can refer to simple-swoole/db
Code example looks not quite good for me, Co\run
approximates to main()
func in C, so, the correct way to do this is that put all of your code in Co\run
.
About question 2, we don’t always need to recycle the connection at the end of each go func. If you want this, just create a new function to wrapper it, we only provide the minimal APIs.
Ok, I understand, many thanks!
I had questions about this example from official docs.
A) Is it accepted to initiate RedisPool outside of
run
and use that instance insiderun\go
? for example:2) On that doc-page there is shown:
Runtime::enableCoroutine();
before runningCoroutine\run
function. Can you tell (or write on that page too), do we always need to execute that command before\run
executions? I thought coroutines were enabled by default.