1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| [root@matrix-cache01 ~] [root@matrix-cache02 ~] local uri_args = ngx.req.get_uri_args() local productId = uri_args["productId"] local shopId = uri_args["shopId"]
local cache_ngx = ngx.shared.my_cache
local productCacheKey = "product_info_"..productId local shopCacheKey = "shop_info_"..shopId
local productCache = cache_ngx:get(productCacheKey) local shopCache = cache_ngx:get(shopCacheKey)
if productCache == "" or productCache == nil then local http = require("resty.http") local httpc = http.new()
local resp, err = httpc:request_uri("http://192.168.31.178:8080",{ method = "GET", path = "/getProductInfo?productId="..productId })
productCache = resp.body cache_ngx:set(productCacheKey, productCache, 10 * 60) end
if shopCache == "" or shopCache == nil then local http = require("resty.http") local httpc = http.new()
local resp, err = httpc:request_uri("http://192.168.31.178:8080",{ method = "GET", path = "/getShopInfo?shopId="..shopId })
shopCache = resp.body cache_ngx:set(shopCacheKey, shopCache, 10 * 60) end
local cjson = require("cjson") local productCacheJSON = cjson.decode(productCache) local shopCacheJSON = cjson.decode(shopCache)
local context = { productId = productCacheJSON.id, productName = productCacheJSON.name, productPrice = productCacheJSON.price, productPictureList = productCacheJSON.pictureList, productSpecification = productCacheJSON.specification, productService = productCacheJSON.service, productColor = productCacheJSON.color, productSize = productCacheJSON.size, shopId = shopCacheJSON.id, shopName = shopCacheJSON.name, shopLevel = shopCacheJSON.level, shopGoodCommentRate = shopCacheJSON.goodCommentRate }
local template = require("resty.template") template.render("product.html", context)
|