Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
php_utils
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
php_utils
Commits
621c41cc
Commit
621c41cc
authored
Jun 24, 2021
by
guozhiyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:add skip locked func
parent
8770af2e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
Medoo.php
src/Mysql/Medoo.php
+49
-0
MysqlBase.php
src/Mysql/MysqlBase.php
+2
-0
No files found.
src/Mysql/Medoo.php
View file @
621c41cc
...
...
@@ -1459,6 +1459,55 @@ class Medoo
return
$result
;
}
public
function
selectForUpdateSkipLocked
(
$table
,
$columns
=
null
,
$where
=
null
,
$options
=
null
)
{
$map
=
[];
$result
=
[];
$column_map
=
[];
$index
=
0
;
$column
=
$columns
;
$is_single
=
(
is_string
(
$column
)
&&
$column
!==
'*'
);
$query
=
$this
->
exec
(
$this
->
selectContext
(
$table
,
$map
,
$columns
,
$where
,
null
,
$options
)
.
' FOR UPDATE SKIP LOCKED '
,
$map
);
$this
->
columnMap
(
$columns
,
$column_map
,
true
);
if
(
!
$this
->
statement
)
{
return
false
;
}
if
(
$columns
===
'*'
)
{
return
$query
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
}
while
(
$data
=
$query
->
fetch
(
PDO
::
FETCH_ASSOC
))
{
$current_stack
=
[];
$this
->
dataMap
(
$data
,
$columns
,
$column_map
,
$current_stack
,
true
,
$result
);
}
if
(
$is_single
)
{
$single_result
=
[];
$result_key
=
$column_map
[
$column
][
0
];
foreach
(
$result
as
$item
)
{
$single_result
[]
=
$item
[
$result_key
];
}
return
$single_result
;
}
return
$result
;
}
public
function
insert
(
$table
,
$datas
)
{
$stack
=
[];
...
...
src/Mysql/MysqlBase.php
View file @
621c41cc
...
...
@@ -37,6 +37,7 @@ use Api\PhpUtils\Log\FileLog;
* @method static MysqlBase select($columns, $where, $options)
* @method static MysqlBase selectMaster($columns, $where, $options)
* @method static MysqlBase selectForUpdate($columns, $where, $options)
* * @method static MysqlBase selectForUpdateSkipLocked($columns, $where, $options)
* @method static MysqlBase getMaster($columns, $where, $options)
* @method static MysqlBase get($columns, $where, $options)
* @method static MysqlBase count($columns, $where)
...
...
@@ -105,6 +106,7 @@ abstract class MysqlBase
"selectMaster"
,
// 或使用/*master*/强制路由,对主从实时性要求较高的场景使用,分布式系统尽量用消息代替查主库等其他方案
"getMaster"
,
"selectForUpdate"
,
"selectForUpdateSkipLocked"
,
"insertDuplicate"
,
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment