|
@@ -8,6 +8,7 @@ import com.yoho.core.redis.cluster.operations.nosync.YHZSetOperations; |
|
@@ -8,6 +8,7 @@ import com.yoho.core.redis.cluster.operations.nosync.YHZSetOperations; |
8
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
8
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
9
|
import com.yohoufo.common.cache.CacheHelper;
|
9
|
import com.yohoufo.common.cache.CacheHelper;
|
10
|
import com.yohoufo.common.cache.CacheKeyEnum;
|
10
|
import com.yohoufo.common.cache.CacheKeyEnum;
|
|
|
11
|
+import com.yohoufo.common.utils.DateUtil;
|
11
|
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
|
12
|
import com.yohoufo.dal.user.model.UserAuthorizeInfo;
|
12
|
import com.yohoufo.dal.user.model.UserFavorite;
|
13
|
import com.yohoufo.dal.user.model.UserFavorite;
|
13
|
import com.yohoufo.dal.user.model.UserFavoriteSku;
|
14
|
import com.yohoufo.dal.user.model.UserFavoriteSku;
|
|
@@ -61,6 +62,11 @@ public class CacheService { |
|
@@ -61,6 +62,11 @@ public class CacheService { |
61
|
return RedisKeyBuilder.newInstance().appendFixed(CacheKeyEnum.USER_SKU_FAVORITE_ZSET_KEY.getCacheKey()).appendVar(uid);
|
62
|
return RedisKeyBuilder.newInstance().appendFixed(CacheKeyEnum.USER_SKU_FAVORITE_ZSET_KEY.getCacheKey()).appendVar(uid);
|
62
|
}
|
63
|
}
|
63
|
|
64
|
|
|
|
65
|
+ /////// 相关的key构造
|
|
|
66
|
+ public static RedisKeyBuilder getSkuFavoriteFlagRedisKeyBuilder(Integer uid, Integer storageId){
|
|
|
67
|
+ return RedisKeyBuilder.newInstance().appendFixed(CacheKeyEnum.USER_SKU_FAVORITE_FLAG_KEY.getCacheKey()).appendVarWithMH(uid).appendVar(storageId);
|
|
|
68
|
+ }
|
|
|
69
|
+
|
64
|
/**************************************************************************
|
70
|
/**************************************************************************
|
65
|
* 商品收藏相关
|
71
|
* 商品收藏相关
|
66
|
*************************************************************************/
|
72
|
*************************************************************************/
|
|
@@ -428,6 +434,18 @@ public class CacheService { |
|
@@ -428,6 +434,18 @@ public class CacheService { |
428
|
return set;
|
434
|
return set;
|
429
|
}
|
435
|
}
|
430
|
|
436
|
|
|
|
437
|
+
|
|
|
438
|
+ public boolean setNxKey(Integer userId, Integer storageId) {
|
|
|
439
|
+ Boolean aBoolean = yhValueOperations.setIfAbsent(getSkuFavoriteFlagRedisKeyBuilder(userId, storageId), String.valueOf(DateUtil.getCurrentTimeSecond()));
|
|
|
440
|
+ if (aBoolean) {
|
|
|
441
|
+ yhRedisTemplate.longExpire(getSkuFavoriteFlagRedisKeyBuilder(userId, storageId),
|
|
|
442
|
+ CacheKeyEnum.USER_SKU_FAVORITE_FLAG_KEY.getDefaultExpireTime(),
|
|
|
443
|
+ CacheKeyEnum.USER_SKU_FAVORITE_FLAG_KEY.getTimeUnit());
|
|
|
444
|
+ }
|
|
|
445
|
+
|
|
|
446
|
+ return aBoolean;
|
|
|
447
|
+ }
|
|
|
448
|
+
|
431
|
private String getSkuFacoriteValue(Integer storageId, BigDecimal price) {
|
449
|
private String getSkuFacoriteValue(Integer storageId, BigDecimal price) {
|
432
|
StringBuilder sb = new StringBuilder();
|
450
|
StringBuilder sb = new StringBuilder();
|
433
|
sb.append(storageId).append(":").append(price);
|
451
|
sb.append(storageId).append(":").append(price);
|