Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
Tz Tools
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
3121c242
authored
2022-08-23 13:41:56 -0400
by
Jeremy Groot
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
redis and bechmark classes
1 parent
01a7aa84
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
0 deletions
lib/TZBenchMark.php
lib/TZRedis.php
lib/TZBenchMark.php
0 → 100644
View file @
3121c24
<?php
namespace
Tz\WordPress\Tools
;
class
TZBenchMark
{
protected
static
$start_micro
=
0
;
protected
static
$end_micro
=
0
;
static
function
startTimer
()
{
self
::
$start_micro
=
microtime
(
true
);
}
static
function
endTimer
()
{
self
::
$end_micro
=
microtime
(
true
);
}
static
function
logTimer
(
$prepend
=
"TZBENCHMARK TIME ====== "
)
{
error_log
(
$prepend
.
(
self
::
$end_micro
-
self
::
$start_micro
)
.
" seconds"
);
}
}
\ No newline at end of file
lib/TZRedis.php
0 → 100644
View file @
3121c24
<?php
namespace
Tz\WordPress\Tools
;
use
Throwable
;
use
Predis
;
class
TZRedis
{
protected
static
$redis
=
null
;
private
static
$err
=
"TZRedis !!! "
;
private
static
function
connectInstance
()
{
try
{
if
(
!
self
::
$redis
)
{
self
::
$redis
=
new
Predis\Client
();
}
}
catch
(
Throwable
$e
)
{
error_log
(
self
::
$err
.
$e
->
getMessage
());
}
}
static
function
set
(
$key
,
$val
,
$expire
=
60
)
{
try
{
self
::
connectInstance
();
if
(
self
::
$redis
)
{
self
::
$redis
->
set
(
$key
,
$val
,
'ex'
,
$expire
);
}
}
catch
(
Throwable
$e
)
{
error_log
(
self
::
$err
.
"Failed to set "
.
$key
.
" with "
.
$val
);
}
}
static
function
get
(
$key
,
$unserialize
=
false
)
{
try
{
self
::
connectInstance
();
if
(
self
::
$redis
)
{
if
(
$unserialize
)
{
unserialize
(
self
::
$redis
->
get
(
$key
));
}
else
{
return
self
::
$redis
->
get
(
$key
);
}
}
}
catch
(
Throwable
$e
)
{
error_log
(
self
::
$err
.
"Failed to get "
.
$key
);
}
}
static
function
exists
(
$key
)
{
try
{
self
::
connectInstance
();
if
(
self
::
$redis
)
{
return
self
::
$redis
->
exists
(
$key
);
}
}
catch
(
Throwable
$e
)
{
error_log
(
self
::
$err
.
$e
->
getMessage
());
}
}
static
function
clear
(
$key
)
{
try
{
self
::
connectInstance
();
if
(
self
::
$redis
)
{
return
self
::
$redis
->
delete
(
$key
);
}
}
catch
(
Throwable
$e
)
{
error_log
(
self
::
$err
.
$e
->
getMessage
());
}
}
}
\ No newline at end of file
Please
register
or
sign in
to post a comment