mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
add redis wrapper
This commit is contained in:
parent
25fa833495
commit
5b98480950
@ -15,6 +15,7 @@ use ZM\Store\Database\DBException;
|
||||
use ZM\Store\Database\DBQueryBuilder;
|
||||
use ZM\Store\Database\DBWrapper;
|
||||
use ZM\Store\KV\KVInterface;
|
||||
use ZM\Store\KV\Redis\RedisWrapper;
|
||||
|
||||
// 防止重复引用引发报错
|
||||
if (function_exists('zm_internal_errcode')) {
|
||||
@ -216,6 +217,17 @@ function sql_builder(string $name = ''): DBQueryBuilder
|
||||
return (new DBWrapper($name))->createQueryBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Redis 操作类
|
||||
*
|
||||
* @param string $name 使用的 Redis 连接名称
|
||||
* @return RedisWrapper
|
||||
*/
|
||||
function redis(string $name = 'default'): RedisWrapper
|
||||
{
|
||||
return new RedisWrapper($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 / 设置配置项
|
||||
*
|
||||
|
||||
258
src/ZM/Store/KV/Redis/RedisWrapper.php
Normal file
258
src/ZM/Store/KV/Redis/RedisWrapper.php
Normal file
@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\Store\KV\Redis;
|
||||
|
||||
/**
|
||||
* Redis 对象操作的 IDE Helper
|
||||
*
|
||||
* @method acl($subcmd, $args)
|
||||
* @method append($key, $value)
|
||||
* @method auth($auth)
|
||||
* @method bgSave()
|
||||
* @method bgrewriteaof()
|
||||
* @method bitcount($key)
|
||||
* @method bitop($operation, $ret_key, $key, $other_keys)
|
||||
* @method bitpos($key, $bit, $start, $end)
|
||||
* @method blPop($key, $timeout_or_key, $extra_args)
|
||||
* @method brPop($key, $timeout_or_key, $extra_args)
|
||||
* @method brpoplpush($src, $dst, $timeout)
|
||||
* @method bzPopMax($key, $timeout_or_key, $extra_args)
|
||||
* @method bzPopMin($key, $timeout_or_key, $extra_args)
|
||||
* @method clearLastError()
|
||||
* @method client($cmd, $args)
|
||||
* @method close()
|
||||
* @method command($args)
|
||||
* @method config($cmd, $key, $value)
|
||||
* @method connect($host, $port, $timeout, $retry_interval)
|
||||
* @method dbSize()
|
||||
* @method debug($key)
|
||||
* @method decr($key)
|
||||
* @method decrBy($key, $value)
|
||||
* @method del($key, $other_keys)
|
||||
* @method discard()
|
||||
* @method dump($key)
|
||||
* @method echo($msg)
|
||||
* @method eval($script, $args, $num_keys)
|
||||
* @method evalsha($script_sha, $args, $num_keys)
|
||||
* @method exec()
|
||||
* @method exists($key, $other_keys)
|
||||
* @method expire($key, $timeout)
|
||||
* @method expireAt($key, $timestamp)
|
||||
* @method flushAll($async)
|
||||
* @method flushDB($async)
|
||||
* @method geoadd($key, $lng, $lat, $member, $other_triples)
|
||||
* @method geodist($key, $src, $dst, $unit)
|
||||
* @method geohash($key, $member, $other_members)
|
||||
* @method geopos($key, $member, $other_members)
|
||||
* @method georadius($key, $lng, $lan, $radius, $unit, $opts)
|
||||
* @method georadius_ro($key, $lng, $lan, $radius, $unit, $opts)
|
||||
* @method georadiusbymember($key, $member, $radius, $unit, $opts)
|
||||
* @method georadiusbymember_ro($key, $member, $radius, $unit, $opts)
|
||||
* @method get($key)
|
||||
* @method getAuth()
|
||||
* @method getBit($key, $offset)
|
||||
* @method getDBNum()
|
||||
* @method getHost()
|
||||
* @method getLastError()
|
||||
* @method getMode()
|
||||
* @method getOption($option)
|
||||
* @method getPersistentID()
|
||||
* @method getPort()
|
||||
* @method getRange($key, $start, $end)
|
||||
* @method getReadTimeout()
|
||||
* @method getSet($key, $value)
|
||||
* @method getTimeout()
|
||||
* @method hDel($key, $member, $other_members)
|
||||
* @method hExists($key, $member)
|
||||
* @method hGet($key, $member)
|
||||
* @method hGetAll($key)
|
||||
* @method hIncrBy($key, $member, $value)
|
||||
* @method hIncrByFloat($key, $member, $value)
|
||||
* @method hKeys($key)
|
||||
* @method hLen($key)
|
||||
* @method hMget($key, $keys)
|
||||
* @method hMset($key, $pairs)
|
||||
* @method hSet($key, $member, $value)
|
||||
* @method hSetNx($key, $member, $value)
|
||||
* @method hStrLen($key, $member)
|
||||
* @method hVals($key)
|
||||
* @method hscan($str_key, $i_iterator, $str_pattern, $i_count)
|
||||
* @method incr($key)
|
||||
* @method incrBy($key, $value)
|
||||
* @method incrByFloat($key, $value)
|
||||
* @method info($option)
|
||||
* @method isConnected()
|
||||
* @method keys($pattern)
|
||||
* @method lInsert($key, $position, $pivot, $value)
|
||||
* @method lLen($key)
|
||||
* @method lPop($key)
|
||||
* @method lPush($key, $value)
|
||||
* @method lPushx($key, $value)
|
||||
* @method lSet($key, $index, $value)
|
||||
* @method lastSave()
|
||||
* @method lindex($key, $index)
|
||||
* @method lrange($key, $start, $end)
|
||||
* @method lrem($key, $value, $count)
|
||||
* @method ltrim($key, $start, $stop)
|
||||
* @method mget($keys)
|
||||
* @method migrate($host, $port, $key, $db, $timeout, $copy, $replace)
|
||||
* @method move($key, $dbindex)
|
||||
* @method mset($pairs)
|
||||
* @method msetnx($pairs)
|
||||
* @method multi($mode)
|
||||
* @method object($field, $key)
|
||||
* @method pconnect($host, $port, $timeout)
|
||||
* @method persist($key)
|
||||
* @method pexpire($key, $timestamp)
|
||||
* @method pexpireAt($key, $timestamp)
|
||||
* @method pfadd($key, $elements)
|
||||
* @method pfcount($key)
|
||||
* @method pfmerge($dstkey, $keys)
|
||||
* @method ping()
|
||||
* @method pipeline()
|
||||
* @method psetex($key, $expire, $value)
|
||||
* @method psubscribe($patterns, $callback)
|
||||
* @method pttl($key)
|
||||
* @method publish($channel, $message)
|
||||
* @method pubsub($cmd, $args)
|
||||
* @method punsubscribe($pattern, $other_patterns)
|
||||
* @method rPop($key)
|
||||
* @method rPush($key, $value)
|
||||
* @method rPushx($key, $value)
|
||||
* @method randomKey()
|
||||
* @method rawcommand($cmd, $args)
|
||||
* @method rename($key, $newkey)
|
||||
* @method renameNx($key, $newkey)
|
||||
* @method restore($ttl, $key, $value)
|
||||
* @method role()
|
||||
* @method rpoplpush($src, $dst)
|
||||
* @method sAdd($key, $value)
|
||||
* @method sAddArray($key, $options)
|
||||
* @method sDiff($key, $other_keys)
|
||||
* @method sDiffStore($dst, $key, $other_keys)
|
||||
* @method sInter($key, $other_keys)
|
||||
* @method sInterStore($dst, $key, $other_keys)
|
||||
* @method sMembers($key)
|
||||
* @method sMisMember($key, $member, $other_members)
|
||||
* @method sMove($src, $dst, $value)
|
||||
* @method sPop($key)
|
||||
* @method sRandMember($key, $count)
|
||||
* @method sUnion($key, $other_keys)
|
||||
* @method sUnionStore($dst, $key, $other_keys)
|
||||
* @method save()
|
||||
* @method scan($i_iterator, $str_pattern, $i_count)
|
||||
* @method scard($key)
|
||||
* @method script($cmd, $args)
|
||||
* @method select($dbindex)
|
||||
* @method set($key, $value, $opts)
|
||||
* @method setBit($key, $offset, $value)
|
||||
* @method setOption($option, $value)
|
||||
* @method setRange($key, $offset, $value)
|
||||
* @method setex($key, $expire, $value)
|
||||
* @method setnx($key, $value)
|
||||
* @method sismember($key, $value)
|
||||
* @method slaveof($host, $port)
|
||||
* @method slowlog($arg, $option)
|
||||
* @method sort($key, $options)
|
||||
* @method sortAsc($key, $pattern, $get, $start, $end, $getList)
|
||||
* @method sortAscAlpha($key, $pattern, $get, $start, $end, $getList)
|
||||
* @method sortDesc($key, $pattern, $get, $start, $end, $getList)
|
||||
* @method sortDescAlpha($key, $pattern, $get, $start, $end, $getList)
|
||||
* @method srem($key, $member, $other_members)
|
||||
* @method sscan($str_key, $i_iterator, $str_pattern, $i_count)
|
||||
* @method strlen($key)
|
||||
* @method subscribe($channels, $callback)
|
||||
* @method swapdb($srcdb, $dstdb)
|
||||
* @method time()
|
||||
* @method ttl($key)
|
||||
* @method type($key)
|
||||
* @method unlink($key, $other_keys)
|
||||
* @method unsubscribe($channel, $other_channels)
|
||||
* @method unwatch()
|
||||
* @method wait($numslaves, $timeout)
|
||||
* @method watch($key, $other_keys)
|
||||
* @method xack($str_key, $str_group, $arr_ids)
|
||||
* @method xadd($str_key, $str_id, $arr_fields, $i_maxlen, $boo_approximate)
|
||||
* @method xclaim($str_key, $str_group, $str_consumer, $i_min_idle, $arr_ids, $arr_opts)
|
||||
* @method xdel($str_key, $arr_ids)
|
||||
* @method xgroup($str_operation, $str_key, $str_arg1, $str_arg2, $str_arg3)
|
||||
* @method xinfo($str_cmd, $str_key, $str_group)
|
||||
* @method xlen($key)
|
||||
* @method xpending($str_key, $str_group, $str_start, $str_end, $i_count, $str_consumer)
|
||||
* @method xrange($str_key, $str_start, $str_end, $i_count)
|
||||
* @method xread($arr_streams, $i_count, $i_block)
|
||||
* @method xreadgroup($str_group, $str_consumer, $arr_streams, $i_count, $i_block)
|
||||
* @method xrevrange($str_key, $str_start, $str_end, $i_count)
|
||||
* @method xtrim($str_key, $i_maxlen, $boo_approximate)
|
||||
* @method zAdd($key, $score, $value, $extra_args)
|
||||
* @method zCard($key)
|
||||
* @method zCount($key, $min, $max)
|
||||
* @method zIncrBy($key, $value, $member)
|
||||
* @method zLexCount($key, $min, $max)
|
||||
* @method zPopMax($key)
|
||||
* @method zPopMin($key)
|
||||
* @method zRange($key, $start, $end, $scores)
|
||||
* @method zRangeByLex($key, $min, $max, $offset, $limit)
|
||||
* @method zRangeByScore($key, $start, $end, $options)
|
||||
* @method zRank($key, $member)
|
||||
* @method zRem($key, $member, $other_members)
|
||||
* @method zRemRangeByLex($key, $min, $max)
|
||||
* @method zRemRangeByRank($key, $start, $end)
|
||||
* @method zRemRangeByScore($key, $min, $max)
|
||||
* @method zRevRange($key, $start, $end, $scores)
|
||||
* @method zRevRangeByLex($key, $min, $max, $offset, $limit)
|
||||
* @method zRevRangeByScore($key, $start, $end, $options)
|
||||
* @method zRevRank($key, $member)
|
||||
* @method zScore($key, $member)
|
||||
* @method zinterstore($key, $keys, $weights, $aggregate)
|
||||
* @method zscan($str_key, $i_iterator, $str_pattern, $i_count)
|
||||
* @method zunionstore($key, $keys, $weights, $aggregate)
|
||||
* @method delete($key, $other_keys)
|
||||
* @method evaluate($script, $args, $num_keys)
|
||||
* @method evaluateSha($script_sha, $args, $num_keys)
|
||||
* @method getKeys($pattern)
|
||||
* @method getMultiple($keys)
|
||||
* @method lGet($key, $index)
|
||||
* @method lGetRange($key, $start, $end)
|
||||
* @method lRemove($key, $value, $count)
|
||||
* @method lSize($key)
|
||||
* @method listTrim($key, $start, $stop)
|
||||
* @method open($host, $port, $timeout, $retry_interval)
|
||||
* @method popen($host, $port, $timeout)
|
||||
* @method renameKey($key, $newkey)
|
||||
* @method sContains($key, $value)
|
||||
* @method sGetMembers($key)
|
||||
* @method sRemove($key, $member, $other_members)
|
||||
* @method sSize($key)
|
||||
* @method sendEcho($msg)
|
||||
* @method setTimeout($key, $timeout)
|
||||
* @method substr($key, $start, $end)
|
||||
* @method zDelete($key, $member, $other_members)
|
||||
* @method zDeleteRangeByRank($key, $min, $max)
|
||||
* @method zDeleteRangeByScore($key, $min, $max)
|
||||
* @method zInter($key, $keys, $weights, $aggregate)
|
||||
* @method zRemove($key, $member, $other_members)
|
||||
* @method zRemoveRangeByScore($key, $min, $max)
|
||||
* @method zReverseRange($key, $start, $end, $scores)
|
||||
* @method zSize($key)
|
||||
* @method zUnion($key, $keys, $weights, $aggregate)
|
||||
*/
|
||||
class RedisWrapper
|
||||
{
|
||||
public function __construct(private string $pool = 'default')
|
||||
{
|
||||
}
|
||||
|
||||
public function __call(string $name, array $arguments)
|
||||
{
|
||||
/** @var ZMRedis $pool */
|
||||
$pool = RedisPool::pool($this->pool)->get();
|
||||
if (method_exists($pool, $name)) {
|
||||
$result = $pool->{$name}(...$arguments);
|
||||
}
|
||||
RedisPool::pool($this->pool)->put($pool);
|
||||
return $result ?? false;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user