diff --git a/src/Redis.php b/src/Redis.php index e09a1df..8a4684e 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -20,7 +20,7 @@ public function __construct(array $config = []) $this->score = 0; $this->hashKey = ''; $this->expire = -1; - + $options = [ 'parameters' => [ 'password' => $config['password'] ?? getenv('REDIS_PASSWORD') ?: '', @@ -70,17 +70,17 @@ public function score(int $score): static } /** - * 设置hash的key - * + * 设置hash的key. + * * @return $this */ public function hashKey(string $key): static { $this->hashKey = $key; - + return $this; } - + /** * 设置过期时间. * @@ -117,6 +117,7 @@ public function remember(string $key, callable $callback): mixed // 没有匹配写入cache $return = $callback(); $this->client->zadd($key, $this->score, $return); + return $return; }, 'put' => function ($value) use ($key): void { @@ -129,16 +130,17 @@ public function remember(string $key, callable $callback): mixed if ($hash) { return $hash; } - + // 没有匹配写入cache $return = $callback(); $this->client->hset($key, $this->hashKey, $return); + return $return; }, 'put' => function ($value) use ($key) { $this->client->hset($key, $this->hashKey, $value); - } - ] + }, + ], ]; $getType = (string) $this->client->type($key); diff --git a/tests/RedisTest.php b/tests/RedisTest.php index 973ea92..81734f8 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -7,7 +7,7 @@ ->expire(3600) ->remember('test_zset', function () { return json_encode([ - 'name' => 'test101' + 'name' => 'test101', ]); }); @@ -23,4 +23,4 @@ }); expect($response)->toEqual('jqw4iej6uj48dw8'); -}); \ No newline at end of file +});