Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
jd_data_process
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
28d46554
authored
Oct 28, 2024
by
larosa
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add helper py
parent
79e5ed25
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
2 deletions
helper.py
helper.py
View file @
28d46554
"""
将redis中拓展数据更新到 mysql
"""
import
json
import
redis
import
pymysql
config_dev
=
{
"mysql"
:
{
...
...
@@ -34,9 +36,29 @@ config_prod = {
}
}
def
get_ext_attr_from_redis
(
conf
:
dict
):
"""
1 查找mysql中的platform = 1的数据,去redis中查到是否为拓展属性。
2 对比class_id 下面的attr_id 看是否存在redis中,存在就是拓展属性,否则就是非拓展。
3 拓展属性 is_ext字段改为 2,否则改为1
"""
def
handle_data
(
conf
:
dict
):
select_sql
=
"select class_id from lie_shop_class where platform = 1"
host
=
conf
[
"mysql"
][
"host"
]
port
=
conf
[
"mysql"
][
"port"
]
user
=
conf
[
"mysql"
][
"user"
]
password
=
conf
[
"mysql"
][
"password"
]
database
=
conf
[
"mysql"
][
"database"
]
db
=
pymysql
.
connect
(
host
=
host
,
port
=
port
,
user
=
user
,
password
=
password
,
database
=
database
)
cursor
=
db
.
cursor
()
cursor
.
execute
(
query
=
select_sql
)
db_results
=
cursor
.
fetchall
()
for
i
in
range
(
len
(
db_results
)):
class_id
=
db_results
[
i
][
0
]
redis_host
=
conf
[
"redis"
][
"host"
]
redis_port
=
conf
[
"redis"
][
"port"
]
redis_password
=
conf
[
"redis"
][
"password"
]
redis_db
=
redis
.
Redis
(
host
=
redis_host
,
port
=
redis_port
,
password
=
redis_password
)
redis_db
.
hget
(
"jd_ext_attr"
,
""
)
class_id_str
=
str
(
class_id
)
ans_redis
=
redis_db
.
hget
(
"jd_ext_attr"
,
class_id_str
)
ans_arr
=
json
.
loads
(
ans_redis
)
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