Skip to content

Commit 62aac83

Browse files
committed
2023-10-08
1 parent 9a1f118 commit 62aac83

File tree

2 files changed

+100
-59
lines changed

2 files changed

+100
-59
lines changed

README.md

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ This repo has a tool that help you to manage and write down what you learned in
1313
| Table of Contents | :point_down: |
1414
| -------- | -------- |
1515
| :new: **Top 5 recent learning** | |
16+
| [Cache storage utils using redis server](php/cache-storage-utils-using-redis-server.md) [php] | 2023-10-08 |
1617
| [Getting database from data range to array of enum objects](apps-script/getting-database-from-data-range-to-array-of-enum-objects.md) [apps-script] | 2023-09-03 |
1718
| [JS DOM event deepdive using SvelteJS demo](js/js-dom-event-deepdive-using-sveltejs-demo.md) [js] | 2023-09-01 |
1819
| [ES6 Module import in client browsers](js/es6-module-import-in-client-browsers.md) [js] | 2023-08-29 |
1920
| [SvelteJS : Reactivity via variable assignment](svelte/reactivity-via-assignment-variable.md) [svelte] | 2023-08-28 |
20-
| [Array group by function in JS](js/array-group-by-function-in-js.md) [js] | 2023-08-25 |
2121
| :books: **ansible** [ 1 articles ] | |
2222
| 1. [Run shell command in all hosts](ansible/Run-shell-command-in-all-hosts.md) | 2019-02-18 |
2323
| :books: **apps-script** [ 1 articles ] | |
@@ -119,7 +119,7 @@ This repo has a tool that help you to manage and write down what you learned in
119119
| 76. [List opening ports or listening UNIX sockets](networking/List-opening-ports-or-listening-UNIX-sockets.md) | 2018-02-21 |
120120
| 77. [Setup wildcard domains .test for development in MacOS](networking/Setup-wildcard-domains-.local-for-development-in-MacOS.md) | 2018-04-24 |
121121
| 78. [Use NGINX as a TCP,UDP load balancer](networking/use-nginx-as-a-tcp,udp-load-balancer.md) | 2019-04-03 |
122-
| :books: **php** [ 11 articles ] | |
122+
| :books: **php** [ 12 articles ] | |
123123
| 79. [Eloquent Many-to-Many Relationship](php/Eloquent-Many-to-Many-Relationship.md) | 2015-12-02 |
124124
| 80. [Run built-in server via Docker](php/Run-built-in-server-via-Docker.md) | 2015-12-04 |
125125
| 81. [F-cking stupid limit of input vars](php/Fcking-stupid-limit-of-input-vars.md) | 2016-03-08 |
@@ -131,73 +131,74 @@ This repo has a tool that help you to manage and write down what you learned in
131131
| 87. [Getting back Whoops error pages in Laravel 9](php/getting-back-whoops-error-pages-in-laravel-9.md) | 2022-03-13 |
132132
| 88. [Minimize Google PHP SDK before deploying on production](php/minimize-google-php-sdk-before-deploying-on-production.md) | 2022-03-14 |
133133
| 89. [Laravel run scheduled command within parent environment](php/laravel-run-scheduled-command-within-parent-environment.md) | 2022-03-15 |
134+
| 90. [Cache storage utils using redis server](php/cache-storage-utils-using-redis-server.md) | 2023-10-08 |
134135
| :books: **programming** [ 1 articles ] | |
135-
| 90. [Get random number from computer](programming/Get-random-number-from-computer.md) | 2018-05-14 |
136+
| 91. [Get random number from computer](programming/Get-random-number-from-computer.md) | 2018-05-14 |
136137
| :books: **python** [ 7 articles ] | |
137-
| 91. [String Format Unicode params](python/String-Format-Unicode-params.md) | 2015-12-01 |
138-
| 92. [Reference assign object variable](python/Reference-assign-object-variable.md) | 2015-12-04 |
139-
| 93. [HTTP2 supported for python requests library](python/HTTP2-supported-for-python-requests-library.md) | 2017-08-04 |
140-
| 94. [Exporting environment variables on virtual env activate](python/Exporting-environment-variables-on-virtual-env-activate.md) | 2018-04-30 |
141-
| 95. [Do not use mutable objects as default parameters](python/Do-not-use-mutable-objects-as-default-parameters.md) | 2018-07-24 |
142-
| 96. [Context Managers in Python](python/Context-Managers.md) | 2018-07-24 |
143-
| 97. [Setter and getter behavior of class property in Python3](python/Setter-and-getter-behavior-of-class-property-in-Python3.md) | 2018-07-30 |
138+
| 92. [String Format Unicode params](python/String-Format-Unicode-params.md) | 2015-12-01 |
139+
| 93. [Reference assign object variable](python/Reference-assign-object-variable.md) | 2015-12-04 |
140+
| 94. [HTTP2 supported for python requests library](python/HTTP2-supported-for-python-requests-library.md) | 2017-08-04 |
141+
| 95. [Exporting environment variables on virtual env activate](python/Exporting-environment-variables-on-virtual-env-activate.md) | 2018-04-30 |
142+
| 96. [Do not use mutable objects as default parameters](python/Do-not-use-mutable-objects-as-default-parameters.md) | 2018-07-24 |
143+
| 97. [Context Managers in Python](python/Context-Managers.md) | 2018-07-24 |
144+
| 98. [Setter and getter behavior of class property in Python3](python/Setter-and-getter-behavior-of-class-property-in-Python3.md) | 2018-07-30 |
144145
| :books: **quote** [ 1 articles ] | |
145-
| 98. [Random quote 23 Feb 2017](quote/random-quote-23-feb-2017.md) | 2017-02-23 |
146+
| 99. [Random quote 23 Feb 2017](quote/random-quote-23-feb-2017.md) | 2017-02-23 |
146147
| :books: **redis** [ 1 articles ] | |
147-
| 99. [Transaction style in Redis](redis/Transaction-style-in-Redis.md) | 2018-01-31 |
148+
| 100. [Transaction style in Redis](redis/Transaction-style-in-Redis.md) | 2018-01-31 |
148149
| :books: **svelte** [ 1 articles ] | |
149-
| 100. [SvelteJS : Reactivity via variable assignment](svelte/reactivity-via-assignment-variable.md) | 2023-08-28 |
150+
| 101. [SvelteJS : Reactivity via variable assignment](svelte/reactivity-via-assignment-variable.md) | 2023-08-28 |
150151
| :books: **sysadmin** [ 34 articles ] | |
151-
| 101. [FTP via curl tool](sysadmin/FTP-via-curl-tool.md) | 2015-12-03 |
152-
| 102. [View real-time logs using websocketd](sysadmin/View-real-time-logs-using-websocketd.md) | 2015-12-04 |
153-
| 103. [Commands](sysadmin/Commands.md) | 2015-12-30 |
154-
| 104. [Bash shell shortcuts](sysadmin/Bash-shell-shortcuts.md) | 2016-03-26 |
155-
| 105. [Stats your top-10 frequently commands](sysadmin/Stats-your-top-10-commands.md) | 2016-03-26 |
156-
| 106. [Compressing and Extracting files with rar in Linux](sysadmin/Compressing-and-Extracting-files-with-rar-in-Linux.md) | 2017-05-17 |
157-
| 107. [Grant user to use sudo without password](sysadmin/Grant-user-to-use-sudo-without-password.md) | 2017-05-18 |
158-
| 108. [wget Output flag](sysadmin/wget-Output-flag.md) | 2017-05-19 |
159-
| 109. [Using BSD find util to find and exec command on file and folder](sysadmin/Using-BSD-find-util-to-find-and-exec-command-on-file-and-folder.md) | 2017-05-22 |
160-
| 110. [zcat : decompressing pipe tool](sysadmin/zcat-:-decompressing-pipe-tool.md) | 2017-05-22 |
161-
| 111. [Gearman bash worker and client](sysadmin/gearman-bash-worker-and-client.md) | 2017-06-15 |
162-
| 112. [Cleaning up old linux kernels](sysadmin/Cleaning-up-old-linux-kernels.md) | 2017-08-06 |
163-
| 113. [Create SSH tunnel manually](sysadmin/create-ssh-tunnel-manually.md) | 2017-09-01 |
164-
| 114. [Enable reverse proxy in CentOS](sysadmin/enable-reverse-proxy-in-centos.md) | 2017-09-01 |
165-
| 115. [Ansible playbook : skip to task](sysadmin/ansible-:-skip-to-task.md) | 2017-09-05 |
166-
| 116. [Grep : find a string in folder](sysadmin/grep-:-find-a-string-in-folder.md) | 2017-09-05 |
167-
| 117. [Lock and unlock a user password](sysadmin/lock-and-unlock-a-user-password.md) | 2017-09-07 |
168-
| 118. [Generate dhparam file faster](sysadmin/generate-dhparam-file-faster.md) | 2017-09-07 |
169-
| 119. [Blocking specified country to prevent from DDOS](sysadmin/blocking-specified-country-to-prevent-from-ddos.md) | 2017-09-25 |
170-
| 120. [BASH exiting on first error](sysadmin/bash-exiting-on-first-error.md) | 2017-09-26 |
171-
| 121. [BASH return a value in function](sysadmin/bash-return-a-value-in-function.md) | 2017-09-26 |
172-
| 122. [BASH tracing commands](sysadmin/BASH-tracing-commands.md) | 2017-09-27 |
173-
| 123. [TIME command output meaning](sysadmin/time-command-output-meaning.md) | 2017-10-04 |
174-
| 124. [Using netcat as tiny TCP debug tool](sysadmin/using-netcat-as-tiny-tcp-debug-tool.md) | 2017-10-07 |
175-
| 125. [Getting your external IP](sysadmin/Getting-your-external-IP.md) | 2017-11-24 |
176-
| 126. [Use journalctl to check system logs](sysadmin/Use-journalctl-to-check-system-logs.md) | 2018-01-22 |
177-
| 127. [Prevent source hacking from .git directory exposing](sysadmin/prevent-source-hacking-from-.git-directory-exposing.md) | 2018-03-01 |
178-
| 128. [Cut file content from line to line](sysadmin/Cut-file-content-from-line-to-line.md) | 2018-03-25 |
179-
| 129. [Prepend line number to file](sysadmin/Prepend-line-number-to-file.md) | 2018-03-25 |
180-
| 130. [Create a sequence of numbers](sysadmin/Create-a-sequence-of-numbers.md) | 2018-03-25 |
181-
| 131. [Send a file through networking via netcat](sysadmin/Send-a-file-through-networking-via-netcat.md) | 2018-04-10 |
182-
| 132. [Create tiny chat channel via netcat](sysadmin/Create-tiny-chat-channel-via-netcat.md) | 2018-04-10 |
183-
| 133. [View DNS history of a domain](sysadmin/View-DNS-history-of-a-domain.md) | 2018-05-08 |
184-
| 134. [Curl override Name Resolution with specific IP address](sysadmin/Curl-override-Name-Resolution-with-specific-IP-address.md) | 2018-08-18 |
152+
| 102. [FTP via curl tool](sysadmin/FTP-via-curl-tool.md) | 2015-12-03 |
153+
| 103. [View real-time logs using websocketd](sysadmin/View-real-time-logs-using-websocketd.md) | 2015-12-04 |
154+
| 104. [Commands](sysadmin/Commands.md) | 2015-12-30 |
155+
| 105. [Bash shell shortcuts](sysadmin/Bash-shell-shortcuts.md) | 2016-03-26 |
156+
| 106. [Stats your top-10 frequently commands](sysadmin/Stats-your-top-10-commands.md) | 2016-03-26 |
157+
| 107. [Compressing and Extracting files with rar in Linux](sysadmin/Compressing-and-Extracting-files-with-rar-in-Linux.md) | 2017-05-17 |
158+
| 108. [Grant user to use sudo without password](sysadmin/Grant-user-to-use-sudo-without-password.md) | 2017-05-18 |
159+
| 109. [wget Output flag](sysadmin/wget-Output-flag.md) | 2017-05-19 |
160+
| 110. [Using BSD find util to find and exec command on file and folder](sysadmin/Using-BSD-find-util-to-find-and-exec-command-on-file-and-folder.md) | 2017-05-22 |
161+
| 111. [zcat : decompressing pipe tool](sysadmin/zcat-:-decompressing-pipe-tool.md) | 2017-05-22 |
162+
| 112. [Gearman bash worker and client](sysadmin/gearman-bash-worker-and-client.md) | 2017-06-15 |
163+
| 113. [Cleaning up old linux kernels](sysadmin/Cleaning-up-old-linux-kernels.md) | 2017-08-06 |
164+
| 114. [Create SSH tunnel manually](sysadmin/create-ssh-tunnel-manually.md) | 2017-09-01 |
165+
| 115. [Enable reverse proxy in CentOS](sysadmin/enable-reverse-proxy-in-centos.md) | 2017-09-01 |
166+
| 116. [Ansible playbook : skip to task](sysadmin/ansible-:-skip-to-task.md) | 2017-09-05 |
167+
| 117. [Grep : find a string in folder](sysadmin/grep-:-find-a-string-in-folder.md) | 2017-09-05 |
168+
| 118. [Lock and unlock a user password](sysadmin/lock-and-unlock-a-user-password.md) | 2017-09-07 |
169+
| 119. [Generate dhparam file faster](sysadmin/generate-dhparam-file-faster.md) | 2017-09-07 |
170+
| 120. [Blocking specified country to prevent from DDOS](sysadmin/blocking-specified-country-to-prevent-from-ddos.md) | 2017-09-25 |
171+
| 121. [BASH exiting on first error](sysadmin/bash-exiting-on-first-error.md) | 2017-09-26 |
172+
| 122. [BASH return a value in function](sysadmin/bash-return-a-value-in-function.md) | 2017-09-26 |
173+
| 123. [BASH tracing commands](sysadmin/BASH-tracing-commands.md) | 2017-09-27 |
174+
| 124. [TIME command output meaning](sysadmin/time-command-output-meaning.md) | 2017-10-04 |
175+
| 125. [Using netcat as tiny TCP debug tool](sysadmin/using-netcat-as-tiny-tcp-debug-tool.md) | 2017-10-07 |
176+
| 126. [Getting your external IP](sysadmin/Getting-your-external-IP.md) | 2017-11-24 |
177+
| 127. [Use journalctl to check system logs](sysadmin/Use-journalctl-to-check-system-logs.md) | 2018-01-22 |
178+
| 128. [Prevent source hacking from .git directory exposing](sysadmin/prevent-source-hacking-from-.git-directory-exposing.md) | 2018-03-01 |
179+
| 129. [Cut file content from line to line](sysadmin/Cut-file-content-from-line-to-line.md) | 2018-03-25 |
180+
| 130. [Prepend line number to file](sysadmin/Prepend-line-number-to-file.md) | 2018-03-25 |
181+
| 131. [Create a sequence of numbers](sysadmin/Create-a-sequence-of-numbers.md) | 2018-03-25 |
182+
| 132. [Send a file through networking via netcat](sysadmin/Send-a-file-through-networking-via-netcat.md) | 2018-04-10 |
183+
| 133. [Create tiny chat channel via netcat](sysadmin/Create-tiny-chat-channel-via-netcat.md) | 2018-04-10 |
184+
| 134. [View DNS history of a domain](sysadmin/View-DNS-history-of-a-domain.md) | 2018-05-08 |
185+
| 135. [Curl override Name Resolution with specific IP address](sysadmin/Curl-override-Name-Resolution-with-specific-IP-address.md) | 2018-08-18 |
185186
| :books: **tools** [ 2 articles ] | |
186-
| 135. [Base 64 encode and decode builtin tool](tools/base-64-encode-and-decode-builtin-tool.md) | 2017-04-21 |
187-
| 136. [Zip compressing list of files](tools/zip-compressing-list-of-files.md) | 2017-09-25 |
187+
| 136. [Base 64 encode and decode builtin tool](tools/base-64-encode-and-decode-builtin-tool.md) | 2017-04-21 |
188+
| 137. [Zip compressing list of files](tools/zip-compressing-list-of-files.md) | 2017-09-25 |
188189
| :books: **varnish** [ 1 articles ] | |
189-
| 137. [Check vcl file syntax before restarting](varnish/Check-vcl-file-syntax-before-restarting.md) | 2018-01-31 |
190+
| 138. [Check vcl file syntax before restarting](varnish/Check-vcl-file-syntax-before-restarting.md) | 2018-01-31 |
190191
| :books: **vim** [ 2 articles ] | |
191-
| 138. [Using mark to bookmark checkpoints in files](vim/Using-mark-to-bookmark-checkpoints-in-files.md) | 2018-01-30 |
192-
| 139. [Convert tabs to spaces](vim/Convert-tabs-to-spaces.md) | 2018-02-21 |
192+
| 139. [Using mark to bookmark checkpoints in files](vim/Using-mark-to-bookmark-checkpoints-in-files.md) | 2018-01-30 |
193+
| 140. [Convert tabs to spaces](vim/Convert-tabs-to-spaces.md) | 2018-02-21 |
193194
| :books: **web** [ 7 articles ] | |
194-
| 140. [Cloudflare Error 522 Connection Time out](web/Cloudflare-Error-522-Connection-Time-out.md) | 2017-05-18 |
195-
| 141. [Ping Google to crawl updated content](web/ping-google-to-crawl-updated-content.md) | 2017-08-08 |
196-
| 142. [Using web proxy to bypass firewalls](web/Using-web-proxy-to-bypass-firewalls.md) | 2017-12-07 |
197-
| 143. [HSTS rule in browser](web/HSTS-rule-in-browser.md) | 2018-01-03 |
198-
| 144. [Bypass CORS by using JSONP callback](web/Bypass-CORS-by-using-JSONP-callback.md) | 2018-01-08 |
199-
| 145. [Sending Cookie in AJAX CORs request](web/sending-cookie-in-ajax-cors-request.md) | 2018-03-01 |
200-
| 146. [Can not get real IP address from Load Balancer SSL Passthrough](web/Can-not-get-real-IP-address-from-Load-Balancer-SSL-Passthrough.md) | 2019-03-14 |
195+
| 141. [Cloudflare Error 522 Connection Time out](web/Cloudflare-Error-522-Connection-Time-out.md) | 2017-05-18 |
196+
| 142. [Ping Google to crawl updated content](web/ping-google-to-crawl-updated-content.md) | 2017-08-08 |
197+
| 143. [Using web proxy to bypass firewalls](web/Using-web-proxy-to-bypass-firewalls.md) | 2017-12-07 |
198+
| 144. [HSTS rule in browser](web/HSTS-rule-in-browser.md) | 2018-01-03 |
199+
| 145. [Bypass CORS by using JSONP callback](web/Bypass-CORS-by-using-JSONP-callback.md) | 2018-01-08 |
200+
| 146. [Sending Cookie in AJAX CORs request](web/sending-cookie-in-ajax-cors-request.md) | 2018-03-01 |
201+
| 147. [Can not get real IP address from Load Balancer SSL Passthrough](web/Can-not-get-real-IP-address-from-Load-Balancer-SSL-Passthrough.md) | 2019-03-14 |
201202

202203

203204
# Instruction
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
- Date : 2023-10-08
2+
- Tags : #php #cache #redis
3+
4+
## Cache storage utils using redis server
5+
6+
I created a small util Cache storage using redis server to cache seriable data, it stores **serialzied data string** in text then **unserialize** to wake the data up.
7+
8+
```php
9+
<?php
10+
11+
namespace App\Library;
12+
13+
use Predis\Client;
14+
use Predis\PredisException;
15+
16+
class CacheStorage
17+
{
18+
public function __construct(private Client $redis)
19+
{
20+
}
21+
22+
public function remember($key, $ttl, $dataFn)
23+
{
24+
try {
25+
$cached = $this->redis->get($key);
26+
27+
if ($cached) {
28+
return unserialize($cached);
29+
}
30+
31+
$data = $dataFn();
32+
$this->redis->set($key, serialize($data), "ex", $ttl);
33+
34+
return $data;
35+
} catch (PredisException $e) {
36+
return $dataFn();
37+
}
38+
}
39+
}
40+
```

0 commit comments

Comments
 (0)