Passed
Push — master ( 71f2f4...c227b6 )
by Stephen
01:09 queued 10s
created

redisKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
use Illuminate\Support\Facades\View;
4
use Sfneal\Helpers\Redis\RedisCache;
5
6
/**
7
 * Retrieve a formatted RedisKey with the environment prefix included.
8
 *
9
 * @param string $key
10
 * @return string
11
 */
12
function redisKey(string $key): string
13
{
14
    return RedisCache::key($key);
15
}
16
17
/**
18
 * Get items from the cache.
19
 *
20
 * @param string $key
21
 * @return mixed
22
 */
23
function redisGet(string $key)
24
{
25
    return RedisCache::get($key);
26
}
27
28
/**
29
 * Put items in the cache with a TTL.
30
 *
31
 * Use's environment's REDIS_KEY_EXPIRATION value if $expiration is null.
32
 *
33
 * @param string $key
34
 * @param mixed|null $value
35
 * @param int|null $expiration
36
 * @return mixed|null $value
37
 */
38
function redisSet(string $key, $value = null, $expiration = null)
39
{
40
    return RedisCache::set($key, $value, $expiration);
41
}
42
43
/**
44
 * Add a TTL attribute (time to live or time til expiration) to a Redis key.
45
 *
46
 * @param string $key
47
 * @param null $expiration
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $expiration is correct as it would always require null to be passed?
Loading history...
48
 * @return mixed
49
 */
50
function redisExpire(string $key, $expiration = null)
51
{
52
    return RedisCache::expire($key, $expiration);
53
}
54
55
/**
56
 * Delete Redis key's from the Cache.
57
 *
58
 * @param $key array|string
59
 * @return array
60
 */
61
function redisDelete($key): array
62
{
63
    return RedisCache::delete($key);
64
}
65
66
/**
67
 * Determine if a redis key exists in the cache.
68
 *
69
 * @param string $key
70
 * @return bool
71
 */
72
function redisExists(string $key): bool
73
{
74
    return RedisCache::exists($key);
75
}
76
77
/**
78
 * Determine if a redis key is missing from the cache.
79
 *
80
 * @param string $key
81
 * @return bool
82
 */
83
function redisMissing(string $key): bool
84
{
85
    return RedisCache::missing($key);
86
}
87
88
/**
89
 * Render a view & cache its output for reuse.
90
 *
91
 * @param string $key
92
 * @param string $view
93
 * @param array $data
94
 * @param int|null $expiration
95
 * @return mixed|null
96
 */
97
function redisCacheView(string $key, string $view, array $data, int $expiration = null)
98
{
99
    return RedisCache::set($key, View::make($view, $data)->render(), $expiration);
100
}
101
102
/**
103
 * Create a Redis Key with a null value if it is missing.
104
 *
105
 * @param string $key
106
 * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
107
 * @param int|null $expiration
108
 * @return bool
109
 */
110
function redisCreateIfMissing(string $key, $value = null, int $expiration = null): bool
111
{
112
    return RedisCache::setIfMissing($key, $value, $expiration);
0 ignored issues
show
Bug introduced by
It seems like $expiration can also be of type integer; however, parameter $expiration of Sfneal\Helpers\Redis\RedisCache::setIfMissing() does only seem to accept null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

112
    return RedisCache::setIfMissing($key, $value, /** @scrutinizer ignore-type */ $expiration);
Loading history...
113
}
114
115
/**
116
 * Increment a Redis Key's value & return the new value.
117
 *
118
 * @param string $key
119
 * @param int $value
120
 * @param int|null $expiration
121
 * @return mixed
122
 */
123
function redisIncrement(string $key, int $value = 1, int $expiration = null)
124
{
125
    return RedisCache::increment($key, $value, $expiration);
126
}
127
128
/**
129
 * Flush the entire redis cache.
130
 *
131
 * @return mixed
132
 */
133
function redisFlush()
134
{
135
    return RedisCache::flush();
136
}
137
138
/**
139
 * Flush the redis cache of all keys with environment's prefix.
140
 *
141
 * @return array
142
 */
143
function redisClearCache(): array
144
{
145
    return RedisCache::clear();
146
}
147
148
/**
149
 * Pass a $callback function to be stored in the Cache for an amount of time.
150
 *
151
 * @param string $key
152
 * @param int $ttl
153
 * @param Closure $callback
154
 * @return mixed
155
 */
156
function redisRemember(string $key, int $ttl, Closure $callback)
157
{
158
    return RedisCache::remember($key, $ttl, $callback);
159
}
160
161
/**
162
 * Pass a $callback function to be stored in the Cache forever.
163
 *
164
 * @param string $key
165
 * @param Closure $callback
166
 * @return mixed
167
 */
168
function redisRememberForever(string $key, Closure $callback)
169
{
170
    return RedisCache::rememberForever($key, $callback);
171
}
172