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