|
|
package com.yohoufo.order.service.cache;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
import com.yohoufo.common.cache.CacheClient;
|
|
|
import com.yohoufo.common.cache.SnappyZipUtils;
|
|
|
import com.yohoufo.order.common.TabType;
|
|
|
import com.yohoufo.order.model.request.OrderListRequest;
|
|
|
import com.yohoufo.order.model.response.OrderDetailInfo;
|
|
|
import com.yohoufo.order.model.response.OrderListInfo;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
...
|
...
|
@@ -25,6 +28,23 @@ public class OrderCacheService { |
|
|
@Autowired
|
|
|
private CacheClient cacheClient;
|
|
|
|
|
|
public void cacheOrderSummary(int uid, TabType actor, Integer cnt){
|
|
|
|
|
|
String hashKey = CacheKeyBuilder.orderListCntHashKey();
|
|
|
String key = CacheKeyBuilder.orderListKey(uid, actor.getValue()).getKey();
|
|
|
try{
|
|
|
cacheClient.hashPut(key, hashKey, cnt, ExpiredTime.ORDER_LIST);
|
|
|
}catch (Exception ex){
|
|
|
logger.warn("in cacheOrderSummary fail ,uid {} actor {} cnt {}", uid, actor, cnt);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Integer getOrderSummary(int uid, TabType actor){
|
|
|
|
|
|
String hashKey = CacheKeyBuilder.orderListCntHashKey();
|
|
|
String key = CacheKeyBuilder.orderListKey(uid, actor.getValue()).getKey();
|
|
|
return cacheClient.hashGet(key, hashKey, Integer.class);
|
|
|
}
|
|
|
|
|
|
public void cacheOrderList(OrderListRequest req, List<OrderListInfo> orderListInfos){
|
|
|
String hashKey = CacheKeyBuilder.orderListHashKey(req);
|
...
|
...
|
@@ -32,7 +52,7 @@ public class OrderCacheService { |
|
|
try{
|
|
|
String hashValue = JSON.toJSONString(orderListInfos);
|
|
|
String compressHashValue = SnappyZipUtils.compress(hashValue);
|
|
|
cacheClient.hashPut(key, hashKey, compressHashValue, 300);
|
|
|
cacheClient.hashPut(key, hashKey, compressHashValue, ExpiredTime.ORDER_LIST);
|
|
|
}catch (Exception ex){
|
|
|
logger.warn("in cacheOrderList fail ,req {}", req);
|
|
|
}
|
...
|
...
|
@@ -58,4 +78,16 @@ public class OrderCacheService { |
|
|
}
|
|
|
|
|
|
|
|
|
public void cacheOrderDetailInfo(int uid, long orderCode, OrderDetailInfo orderDetailInfo){
|
|
|
RedisKeyBuilder kb = CacheKeyBuilder.orderDetailKey(uid, orderCode);
|
|
|
cacheClient.set(kb.getKey(), ExpiredTime.ORDER_DETAIL , orderDetailInfo);
|
|
|
}
|
|
|
|
|
|
|
|
|
public OrderDetailInfo getOrderDetailInfo(int uid, long orderCode){
|
|
|
RedisKeyBuilder kb = CacheKeyBuilder.orderDetailKey(uid, orderCode);
|
|
|
OrderDetailInfo orderDetailInfo = cacheClient.get(kb.getKey(), OrderDetailInfo.class);
|
|
|
return orderDetailInfo;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|