Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support inject redis pool #419

Merged
merged 2 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bean/src/Annotation/Parser/InjectParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ public function parse(int $type, $annotationObject): array

return [$docInject, true];
}
}
}
135 changes: 134 additions & 1 deletion src/redis/src/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,131 @@
use Swoft\Bean\Exception\ContainerException;
use Swoft\Connection\Pool\AbstractPool;
use Swoft\Connection\Pool\Contract\ConnectionInterface;
use Swoft\Connection\Pool\Exception\ConnectionPoolException;

/**
* Class Pool
*
* @since 2.0
*
* @method int append(string $key, string $value)
* @method array blPop(array $keys, int $timeout)
* @method array brPop(array $keys, int $timeout)
* @method string brpoplpush(string $srcKey, string $dstKey, int $timeout)
* @method string decr(string $key)
* @method int decrBy(string $key, int $value)
* @method mixed eval(string $script, array $args = [], int $numKeys = 0)
* @method mixed evalSha(string $scriptSha, array $args = [], int $numKeys = 0)
* @method bool exists(string $key)
* @method int geoAdd(string $key, float $longitude, float $latitude, string $member)
* @method float geoDist(string $key, string $member1, string $member2, string $unit = 'm')
* @method array geohash(string $key, string $member1, string $member2 = null, string $memberN = null)
* @method array geopos(string $key, string $member1, string $member2 = null, string $memberN = null)
* @method mixed|bool get(string $key)
* @method int getBit(string $key, int $offset)
* @method int getOption(string $name)
* @method string getRange(string $key, int $start, int $end)
* @method string getSet(string $key, string $value)
* @method string hDel(string $key, string $hashKey1, string $hashKey2 = null, string $hashKeyN = null)
* @method bool hExists(string $key, string $hashKey)
* @method array hGet(string $key, array $hashKey)
* @method array hGetAll(string $key)
* @method int hIncrBy(string $key, string $hashKey, int $value)
* @method float hIncrByFloat(string $key, string $field, float $increment)
* @method array hKeys(string $key)
* @method int hLen(string $key)
* @method int hSet(string $key, string $hashKey, string $value)
* @method bool hSetNx(string $key, string $hashKey, string $value)
* @method array hVals(string $key)
* @method array hScan(string $key, int &$iterator, string $pattern = null, int $count = 0)
* @method int incr(string $key)
* @method int incrBy(string $key, int $value)
* @method float incrByFloat(string $key, float $increment)
* @method array info(string $option = null)
* @method string|bool lGet(string $key, int $index)
* @method int lInsert(string $key, int $position, string $pivot, string $value)
* @method string|bool lPop(string $key)
* @method int|bool lPush(string $key, string $value1, string $value2 = null, string $valueN = null)
* @method int|bool lPushx(string $key, string $value)
* @method bool lSet(string $key, int $index, string $value)
* @method int msetnx(array $array)
* @method bool persist(string $key)
* @method bool pExpire(string $key, int $ttl)
* @method bool pExpireAt(string $key, int $timestamp)
* @method bool psetex(string $key, int $ttl, $value)
* @method int pttl(string $key)
* @method string rPop(string $key)
* @method int|bool rPush(string $key, string $value1, string $value2 = null, string $valueN = null)
* @method int|bool rPushx(string $key, string $value)
* @method mixed rawCommand(string|array $nodeParams, string $command, mixed $arguments)
* @method bool renameNx(string $srcKey, string $dstKey)
* @method bool restore(string $key, int $ttl, string $value)
* @method string rpoplpush(string $srcKey, string $dstKey)
* @method int sAdd(string $key, string $value1, string $value2 = null, string $valueN = null)
* @method int sAddArray(string $key, array $valueArray)
* @method array sDiff(string $key1, string $key2, string $keyN = null)
* @method int sDiffStore(string $dstKey, string $key1, string $key2, string $keyN = null)
* @method array sInter(string $key1, string $key2, string $keyN = null)
* @method int|bool sInterStore(string $dstKey, string $key1, string $key2, string $keyN = null)
* @method array sMembers(string $key)
* @method bool sMove(string $srcKey, string $dstKey, string $member)
* @method string|bool sPop(string $key)
* @method string|array|bool sRandMember(string $key, int $count = null)
* @method array sUnion(string $key1, string $key2, string $keyN = null)
* @method int sUnionStore(string $dstKey, string $key1, string $key2, string $keyN = null)
* @method array|bool scan(int &$iterator, string $pattern = null, int $count = 0)
* @method mixed script(string|array $nodeParams, string $command, string $script)
* @method bool set(string $key, $value, int $timeout = null)
* @method int setBit(string $key, int $offset, int $value)
* @method string setRange(string $key, int $offset, $value)
* @method int setex(string $key, int $ttl, $value)
* @method bool setnx(string $key, $value)
* @method array sort(string $key, array $option = null)
* @method array sScan(string $key, int &$iterator, string $pattern = null, int $count = 0)
* @method int strlen(string $key)
* @method int ttl(string $key)
* @method int type(string $key)
* @method void unwatch()
* @method void watch(string $key)
* @method int zCard(string $key)
* @method int zCount(string $key, int $start, int $end)
* @method float zIncrBy(string $key, float $value, string $member)
* @method int zLexCount(string $key, int $min, int $max)
* @method array zRange(string $key, int $start, int $end, bool $withscores = null)
* @method array zRangeByLex(string $key, int $min, int $max, int $offset = null, int $limit = null)
* @method array zRangeByScore(string $key, string $start, string $end, array $options = [])
* @method int zRank(string $key, string $member)
* @method array zRemRangeByLex(string $key, int $min, int $max)
* @method array zRevRange(string $key, int $start, int $end, bool $withscore = null)
* @method array zRevRangeByLex(string $key, int $min, int $max, int $offset = null, int $limit = null)
* @method array zRevRangeByScore(string $key, int $start, int $end, array $options = [])
* @method int zRevRank(string $key, string $member)
* @method float zScore(string $key, float $member)
* @method array zScan(string $key, int &$iterator, string $pattern = null, int $count = 0)
* @method int del(string $key1, string $key2 = null, string $key3 = null)
* @method bool expire(string $key, int $ttl)
* @method array keys(string $pattern)
* @method int lLen(string $key)
* @method string|bool lIndex(string $key, int $index)
* @method array lRange(string $key, int $start, int $end)
* @method int|bool lRem(string $key, string $value, int $count)
* @method array|bool lTrim(string $key, int $start, int $stop)
* @method bool rename(string $srcKey, string $dstKey)
* @method int sCard(string $key)
* @method bool sIsMember(string $key, string $value)
* @method int sRem(string $key, string $member1, string $member2 = null, string $memberN = null)
* @method int zRem(string $key, string $member1, string $member2 = null, string $memberN = null)
* @method int zRemRangeByRank(string $key, int $start, int $end)
* @method int zRemRangeByScore(string $key, float|string $start, float|string $end)
* @method int zInterStore(string $Output, array $ZSetKeys, array $Weights = null, string $aggregateFunction = 'SUM')
* @method int zUnionStore(string $Output, array $ZSetKeys, array $Weights = null, string $aggregateFunction = 'SUM')
* @method array hMGet(string $key, array $keys)
* @method bool hMSet(string $key, array $keyValues)
* @method int zAdd(string $key, array $scoreValues)
* @method array mget(array $keys)
* @method bool mset(array $keyValues, int $ttl = 0)
* @method array pipeline(callable $callback)
* @method array transaction(callable $callback)
*/
class Pool extends AbstractPool
{
Expand All @@ -35,4 +155,17 @@ public function createConnection(): ConnectionInterface
{
return $this->redisDb->createConnection($this);
}
}

/**
* call magic method
*
* @param string $name
* @param array $arguments
* @return mixed
* @throws ConnectionPoolException
*/
public function __call(string $name, array $arguments)
{
return $this->getConnection()->$name(...$arguments);
}
}