1
|
|
|
<?php namespace Arcanedev\LaravelSettings\Stores; |
2
|
|
|
|
3
|
|
|
use Illuminate\Redis\RedisManager; |
4
|
|
|
use Illuminate\Support\Arr; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class RedisStore |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\LaravelSettings\Stores |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class RedisStore extends AbstractStore |
13
|
|
|
{ |
14
|
|
|
/* ----------------------------------------------------------------- |
15
|
|
|
| Properties |
16
|
|
|
| ----------------------------------------------------------------- |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The redis manager. |
21
|
|
|
* |
22
|
|
|
* @var \Illuminate\Redis\RedisManager |
23
|
|
|
*/ |
24
|
|
|
protected $manager; |
25
|
|
|
|
26
|
|
|
/* ----------------------------------------------------------------- |
27
|
|
|
| Post-Constructor |
28
|
|
|
| ----------------------------------------------------------------- |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Fire the post options to customize the store. |
33
|
|
|
* |
34
|
|
|
* @param array $options |
35
|
|
|
*/ |
36
|
24 |
|
protected function postOptions(array $options) |
37
|
|
|
{ |
38
|
24 |
|
$this->manager = new RedisManager(Arr::pull($options, 'client', 'predis'), $options); |
39
|
24 |
|
} |
40
|
|
|
|
41
|
|
|
/* ----------------------------------------------------------------- |
42
|
|
|
| Main Methods |
43
|
|
|
| ----------------------------------------------------------------- |
44
|
|
|
*/ |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Read the data from the store. |
48
|
|
|
* |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
24 |
|
protected function read() |
52
|
|
|
{ |
53
|
24 |
|
$data = $this->manager->connection() |
54
|
24 |
|
->command('get', ['settings']); |
55
|
|
|
|
56
|
24 |
|
return is_string($data) ? json_decode($data, true) : []; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Write the data into the store. |
61
|
|
|
* |
62
|
|
|
* @param array $data |
63
|
|
|
*/ |
64
|
24 |
|
protected function write(array $data) |
65
|
|
|
{ |
66
|
24 |
|
$this->manager->connection() |
67
|
24 |
|
->command('set', ['settings', json_encode($data)]); |
68
|
24 |
|
} |
69
|
|
|
} |
70
|
|
|
|