fix
This commit is contained in:
parent
e06fd2da99
commit
9209b00701
BIN
__pycache__/config.cpython-36.pyc
Normal file
BIN
__pycache__/config.cpython-36.pyc
Normal file
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
redis_company_config = {'host': '192.168.100.20', 'port': 6379, 'db': 1}
|
||||
expirt_time = 7200
|
||||
expire_time = 7200
|
||||
mysql_promotion_config = {'user': 'miles', 'pswd': 'aspect', 'host': '192.168.100.30', 'db': 'test'}
|
||||
#mysql_promotion_config = {'user': 'mytga', 'pswd': 'gzVwh4HGR68G', 'host': '10.10.3.5', 'db': 'games_report'}
|
||||
#redis_company_config = {'host': '10.10.3.10', 'port': 6379, 'db': 2}
|
||||
#redis_company_config = {'host': '10.10.3.10', 'port': 6379, 'db': 2}
|
||||
|
BIN
handler/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
handler/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
handler/__pycache__/company.cpython-36.pyc
Normal file
BIN
handler/__pycache__/company.cpython-36.pyc
Normal file
Binary file not shown.
@ -4,14 +4,20 @@ from flask import Flask, jsonify
|
||||
from flask_restful import reqparse, abort, Api, Resource
|
||||
import logging
|
||||
|
||||
from myredis.myredis import company_redis, expirt_time
|
||||
from myredis.myredis import company_redis, expire_time
|
||||
from mysql.mmysql import MysqlBase
|
||||
from config import mysql_promotion_config
|
||||
|
||||
import pdb
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
mydb = MysqlBase(**mysql_promotion_config)
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('comp_id')
|
||||
parser.add_argument('id')
|
||||
parser.add_argument('name')
|
||||
parser.add_argument('contact')
|
||||
parser.add_argument('appid')
|
||||
parser.add_argument('appkey')
|
||||
|
||||
|
||||
# # 操作(put / get / delete)单一资源Todo
|
||||
@ -20,14 +26,16 @@ class Company(Resource):
|
||||
def get(self, comp_id):
|
||||
try:
|
||||
data = company_redis.hmget(comp_id, ['id', 'name', 'contact', 'appid', 'appkey'])
|
||||
log.info(f"get data from redis was {data}")
|
||||
if not data:
|
||||
sql = f"select id,name,contact,appid,appkey from company where id={comp_id};"
|
||||
data = mydb.query(sql)
|
||||
|
||||
log.info(f"get data from db was {data}")
|
||||
company = {}
|
||||
company['id'], company['name'], company['contact'], company['appid'], company['appkey'] = data
|
||||
company_redis.hmset(company['id'], company)
|
||||
company_redis.expire(company['id'], expirt_time)
|
||||
company_redis.expire(company['id'], expire_time)
|
||||
except Exception:
|
||||
log.error(f"get company id {comp_id} failed! ", exc_info=True)
|
||||
return jsonify({'code': 0})
|
||||
@ -35,7 +43,7 @@ class Company(Resource):
|
||||
|
||||
def delete(self, comp_id):
|
||||
try:
|
||||
company_redis.expirt(comp_id, 0)
|
||||
company_redis.expire(comp_id, 0)
|
||||
del_sql = f'delete from company where id={comp_id};'
|
||||
mydb.query(del_sql)
|
||||
except Exception:
|
||||
@ -48,15 +56,15 @@ class Company(Resource):
|
||||
try:
|
||||
company = {}
|
||||
company['id'] = comp_id
|
||||
company['name'] = args['name']
|
||||
company['contact'] = args['contact']
|
||||
company['appid'] = args['appid']
|
||||
company['appkey'] = args['appkey']
|
||||
company['name'] = args.name
|
||||
company['contact'] = args.contact
|
||||
company['appid'] = args.appid
|
||||
company['appkey'] = args.appkey
|
||||
# insert to mysql
|
||||
mydb.insert("company", company)
|
||||
# insert to redsi
|
||||
company_redis.hmset(company['id'], company)
|
||||
company_redis.expirt(company['id'], expirt_time)
|
||||
company_redis.expire(company['id'], expire_time)
|
||||
except Exception:
|
||||
log.error("set values to company mysql/redis failed!", exc_info=True)
|
||||
return jsonify({'code': 0})
|
||||
@ -77,7 +85,7 @@ class Company(Resource):
|
||||
mydb.query("company", update_sql)
|
||||
# update redsi
|
||||
company_redis.hmset(company['id'], company)
|
||||
company_redis.expirt(company['id'], expirt_time)
|
||||
company_redis.expire(company['id'], expire_time)
|
||||
except Exception:
|
||||
log.error("update values to company redis,mysql failed!", exc_info=True)
|
||||
return jsonify({'code': 0})
|
||||
@ -92,6 +100,7 @@ class CompanyList(Resource):
|
||||
|
||||
def post(self):
|
||||
args = parser.parse_args()
|
||||
log.info(f"args was {args}")
|
||||
try:
|
||||
company_redis.rpush("ALL_Company", args['company'])
|
||||
except Exception:
|
||||
|
BIN
log/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
log/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
log/__pycache__/mylog.cpython-36.pyc
Normal file
BIN
log/__pycache__/mylog.cpython-36.pyc
Normal file
Binary file not shown.
BIN
myredis/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
myredis/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
myredis/__pycache__/myredis.cpython-36.pyc
Normal file
BIN
myredis/__pycache__/myredis.cpython-36.pyc
Normal file
Binary file not shown.
@ -2,7 +2,7 @@
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
import redis
|
||||
from config import redis_company_config, expirt_time
|
||||
from config import redis_company_config, expire_time
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -10,4 +10,4 @@ pool = redis.ConnectionPool(host=redis_company_config['host'], port=redis_compan
|
||||
db=redis_company_config['db'], decode_responses=True)
|
||||
|
||||
company_redis = redis.Redis(connection_pool=pool)
|
||||
expirt_time = expirt_time
|
||||
expire_time = expire_time
|
||||
|
BIN
mysql/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
mysql/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
mysql/__pycache__/mmysql.cpython-36.pyc
Normal file
BIN
mysql/__pycache__/mmysql.cpython-36.pyc
Normal file
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
from __future__ import absolute_import
|
||||
"""
|
||||
date: 2016/07/11
|
||||
role: mysql的增删改查类
|
||||
@ -12,7 +12,6 @@ usage: m = mysqlBase(host='xxx',db='xxx',user='xxx',pwd='xxx') 实例化
|
||||
m.query("select * from core")
|
||||
"""
|
||||
import warnings
|
||||
from __future__ import absolute_import
|
||||
|
||||
try:
|
||||
import MySQLdb
|
||||
@ -70,7 +69,7 @@ class MysqlBase:
|
||||
self.curs.execute(_sql)
|
||||
###提交
|
||||
self.conn.commit()
|
||||
# log.info('%s insert ' % _sql)
|
||||
log.info('%s insert ' % _sql)
|
||||
|
||||
except:
|
||||
self.conn.rollback()
|
||||
|
BIN
redis/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
redis/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
redis/__pycache__/myredis.cpython-36.pyc
Normal file
BIN
redis/__pycache__/myredis.cpython-36.pyc
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user