Skip to content

Commit 0fd5aa4

Browse files
committed
The wrapper works
- Using PhpRedisConnection at illuminate/redis:v6.2.0 as base connection
0 parents  commit 0fd5aa4

File tree

11 files changed

+3005
-0
lines changed

11 files changed

+3005
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vendor
2+
composer.lock
3+
4+
# PhpStorm
5+
.idea

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2019 TapTap, https://github.com/TapTap <support@taptap.com>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
A Laravel redis wrapper library for phpredis
2+
=======================
3+
4+
Make PhpRedis match Predis method signature
5+
6+
## Requirement
7+
8+
- PHP 7.1+
9+
- PhpRedis
10+
- Laravel 5.4
11+
12+
## Installation
13+
14+
Install via composer
15+
```
16+
composer require taptap/laravel-phpredis:^1.0
17+
```
18+
19+
Add provider to `config/app.php` and comment out `Illuminate\Redis\RedisServiceProvider`
20+
```php
21+
'providers' => [
22+
...
23+
// Illuminate\Redis\RedisServiceProvider::class,
24+
\TapTap\LaravelRedis\RedisServiceProvider::class,
25+
...
26+
]
27+
```
28+
29+
That's all!

composer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "taptap/laravel-phpredis",
3+
"type": "library",
4+
"description": "A Laravel redis wrapper library for phpredis",
5+
"keywords": [
6+
"laravel",
7+
"phpredis",
8+
"redis"
9+
],
10+
"license": "MIT",
11+
"require": {
12+
"php": ">=7.1",
13+
"ext-redis": "*",
14+
"illuminate/redis": "5.4.*"
15+
},
16+
"require-dev": {
17+
"phpunit/phpunit": "^7.5"
18+
},
19+
"config": {
20+
"sort-packages": true
21+
},
22+
"extra": {
23+
"laravel": {
24+
"providers": [
25+
"TapTap\\LaravelRedis\\RedisServiceProvider"
26+
]
27+
}
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"TapTap\\LaravelRedis\\": "src"
32+
}
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"TapTap\\LaravelRedis\\": "tests"
37+
}
38+
}
39+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace TapTap\LaravelRedis\Connections;
4+
5+
use Redis;
6+
use RedisCluster;
7+
8+
/**
9+
* Wrapper functions in order to match \Predis\ClientInterface
10+
*
11+
* @see ClientInterface
12+
* @see Redis
13+
* @see RedisCluster
14+
*/
15+
class PhpRedisClusterConnection extends PhpRedisConnection
16+
{
17+
/**
18+
* @var RedisCluster
19+
*/
20+
protected $client;
21+
22+
public function exists(...$key)
23+
{
24+
$result = 0;
25+
26+
if (count($key) === 1) {
27+
if (is_array($key[0])) {
28+
foreach ($key[0] as $k) {
29+
$r = $this->client->exists($k);
30+
if ($r) {
31+
++$result;
32+
}
33+
}
34+
} else {
35+
$r = $this->client->exists($key[0]);
36+
if ($r) {
37+
++$result;
38+
}
39+
}
40+
} else {
41+
foreach ($key as $k) {
42+
$r = $this->client->exists($k);
43+
if ($r) {
44+
++$result;
45+
}
46+
}
47+
}
48+
49+
return $result;
50+
}
51+
}

0 commit comments

Comments
 (0)