Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
unify_api2
Project
Project
Details
Activity
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
chaonan
unify_api2
Commits
ac110535
Commit
ac110535
authored
Jun 28, 2023
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change batch redis hmget to pipeline 2023-6-28
parent
63a143d0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
3 deletions
+28
-3
electric_service.py
unify_api/modules/electric/service/electric_service.py
+28
-3
No files found.
unify_api/modules/electric/service/electric_service.py
View file @
ac110535
import
json
import
math
import
pandas
as
pd
import
pendulum
from
pot_libs.settings
import
SETTING
...
...
@@ -559,7 +561,17 @@ async def batch_load_rt_ele(mtids):
try
:
db
=
SETTING
.
mysql_db
keys
=
[
f
"real_time:electric:{db}:{mtid}"
for
mtid
in
mtids
]
for
rt_ele
in
await
RedisUtils
()
.
mget
(
keys
):
i_size
=
500
lst_rt_ele
=
[]
for
i
in
range
(
math
.
ceil
(
len
(
mtids
)
/
i_size
)):
pipe
=
await
RedisUtils
()
.
client
.
pipeline
()
for
key
in
keys
[
i_size
*
i
:
i_size
*
(
i
+
1
)]:
await
pipe
.
get
(
key
)
lst_rt_ele
+=
await
pipe
.
execute
()
for
rt_ele
in
lst_rt_ele
:
if
rt_ele
is
None
:
continue
...
...
@@ -581,8 +593,21 @@ async def batch_load_rt_ele_with_hr(mtids):
keys
=
[
f
"real_time:electric:{db}:{mtid}"
for
mtid
in
mtids
]
key_hrs
=
[
f
"real_time:electric_hr:{db}:{mtid}"
for
mtid
in
mtids
]
lst_rt_ele
=
await
RedisUtils
()
.
mget
(
keys
)
lst_rt_ele_hr
=
await
RedisUtils
()
.
mget
(
key_hrs
)
i_size
=
500
lst_rt_ele
,
lst_rt_ele_hr
=
[],
[]
for
i
in
range
(
math
.
ceil
(
len
(
mtids
)
/
i_size
)):
pipe
=
await
RedisUtils
()
.
client
.
pipeline
()
for
key
in
keys
[
i_size
*
i
:
i_size
*
(
i
+
1
)]:
await
pipe
.
get
(
key
)
lst_rt_ele
+=
await
pipe
.
execute
()
pipe
=
await
RedisUtils
()
.
client
.
pipeline
()
for
key
in
key_hrs
[
i_size
*
i
:
i_size
*
(
i
+
1
)]:
await
pipe
.
get
(
key
)
lst_rt_ele_hr
+=
await
pipe
.
execute
()
for
i
,
mtid
in
enumerate
(
mtids
):
rt_ele
,
rt_ele_hr
=
lst_rt_ele
[
i
],
lst_rt_ele_hr
[
i
]
if
rt_ele
and
rt_ele_hr
:
...
...
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