import pymysql,redis
def selectFromMySQL(_id): #传入产品的id,通过SQL查询
conn = pymysql.Connect(
host = '10.35.165.97',
port = 3306,
user = 'root',
passwd = '123456',
db = 'mydb',
charset = 'utf8'
)
cursor = conn.cursor()
sql = "select _id,proname,price from product where _id=%d"
cursor.execute(sql%_id)
product = cursor.fetchone()
cursor.close()
conn.close()
return product
def selectFromRedis(_id): #从redis中查数据
r = redis.Redis('10.35.165.97',6379)
return r.hgetall('product:info:' + str(_id)) #通过hash的key获得对应的所有field_value
def saveToRedis(product):#将MySQL中查询出的产品信息以hash结构的形式存储于Redis中
r = redis.Redis('10.35.165.97', 637
def selectFromMySQL(_id): #传入产品的id,通过SQL查询
conn = pymysql.Connect(
host = '10.35.165.97',
port = 3306,
user = 'root',
passwd = '123456',
db = 'mydb',
charset = 'utf8'
)
cursor = conn.cursor()
sql = "select _id,proname,price from product where _id=%d"
cursor.execute(sql%_id)
product = cursor.fetchone()
cursor.close()
conn.close()
return product
def selectFromRedis(_id): #从redis中查数据
r = redis.Redis('10.35.165.97',6379)
return r.hgetall('product:info:' + str(_id)) #通过hash的key获得对应的所有field_value
def saveToRedis(product):#将MySQL中查询出的产品信息以hash结构的形式存储于Redis中
r = redis.Redis('10.35.165.97', 637