V getFromMap(String key, K field);
+
+ /**
+ * 将指定的值添加到有序集合中
+ *
+ * @param key 键
+ * @param value 值
+ */
+ void addToSortedSet(String key, String value);
+
+ /**
+ * 获取 Redis 锁(可重入锁)
+ *
+ * @param key 键
+ * @return Lock
+ */
+ RLock getLock(String key);
+
+ /**
+ * 获取 Redis 锁(公平锁)
+ *
+ * @param key 键
+ * @return Lock
+ */
+ RLock getFairLock(String key);
+
+ /**
+ * 获取 Redis 锁(读写锁)
+ *
+ * @param key 键
+ * @return RReadWriteLock
+ */
+ RReadWriteLock getReadWriteLock(String key);
+
+ /**
+ * 获取 Redis 信号量
+ *
+ * @param key 键
+ * @return RSemaphore
+ */
+ RSemaphore getSemaphore(String key);
+
+ /**
+ * 获取 Redis 过期信号量
+ *
+ * 基于Redis的Redisson的分布式信号量(Semaphore)Java对象RSemaphore采用了与java.util.concurrent.Semaphore相似的接口和用法。
+ * 同时还提供了异步(Async)、反射式(Reactive)和RxJava2标准的接口。
+ *
+ * @param key 键
+ * @return RPermitExpirableSemaphore
+ */
+ RPermitExpirableSemaphore getPermitExpirableSemaphore(String key);
+
+ /**
+ * 闭锁
+ *
+ * @param key 键
+ * @return RCountDownLatch
+ */
+ RCountDownLatch getCountDownLatch(String key);
+
+ /**
+ * 布隆过滤器
+ *
+ * @param key 键
+ * @param 存放对象
+ * @return 返回结果
+ */
+ RBloomFilter getBloomFilter(String key);
+
+}
diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/redis/RedisService.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/redis/RedisService.java
new file mode 100644
index 0000000000000000000000000000000000000000..74352dce82402dbf15bc3512c889c25cadc4d7a8
--- /dev/null
+++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/redis/RedisService.java
@@ -0,0 +1,161 @@
+package cn.bugstack.infrastructure.persistent.redis;
+
+import org.redisson.api.*;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.time.Duration;
+
+/**
+ * @description: redisson 相关服务
+ * @author: hdr
+ * @PACKAGE_NAME: cn.bugstack.infrastructure.persistent.redis
+ * @DATE: 2024/4/5
+ */
+@Service("redissonService")
+public class RedisService implements IRedisService {
+
+ @Resource
+ private RedissonClient redissonClient;
+
+ public void setValue(String key, T value) {
+ redissonClient.getBucket(key).set(value);
+ }
+
+ @Override
+ public void setValue(String key, T value, long expired) {
+ RBucket bucket = redissonClient.getBucket(key);
+ bucket.set(value, Duration.ofMillis(expired));
+ }
+
+ public T getValue(String key) {
+ return redissonClient.getBucket(key).get();
+ }
+
+ @Override
+ public RQueue getQueue(String key) {
+ return redissonClient.getQueue(key);
+ }
+
+ @Override
+ public RBlockingQueue getBlockingQueue(String key) {
+ return redissonClient.getBlockingQueue(key);
+ }
+
+ @Override
+ public RDelayedQueue getDelayedQueue(RBlockingQueue rBlockingQueue) {
+ return redissonClient.getDelayedQueue(rBlockingQueue);
+ }
+
+ @Override
+ public long incr(String key) {
+ return redissonClient.getAtomicLong(key).incrementAndGet();
+ }
+
+ @Override
+ public long incrBy(String key, long delta) {
+ return redissonClient.getAtomicLong(key).addAndGet(delta);
+ }
+
+ @Override
+ public long decr(String key) {
+ return redissonClient.getAtomicLong(key).decrementAndGet();
+ }
+
+ @Override
+ public long decrBy(String key, long delta) {
+ return redissonClient.getAtomicLong(key).addAndGet(-delta);
+ }
+
+ @Override
+ public void remove(String key) {
+ redissonClient.getBucket(key).delete();
+ }
+
+ @Override
+ public boolean isExists(String key) {
+ return redissonClient.getBucket(key).isExists();
+ }
+
+ public void addToSet(String key, String value) {
+ RSet set = redissonClient.getSet(key);
+ set.add(value);
+ }
+
+ public boolean isSetMember(String key, String value) {
+ RSet set = redissonClient.getSet(key);
+ return set.contains(value);
+ }
+
+ public void addToList(String key, String value) {
+ RList list = redissonClient.getList(key);
+ list.add(value);
+ }
+
+ public String getFromList(String key, int index) {
+ RList list = redissonClient.getList(key);
+ return list.get(index);
+ }
+
+ @Override
+ public RMap getMap(String key) {
+ return redissonClient.getMap(key);
+ }
+
+ public void addToMap(String key, String field, String value) {
+ RMap map = redissonClient.getMap(key);
+ map.put(field, value);
+ }
+
+ public String getFromMap(String key, String field) {
+ RMap map = redissonClient.getMap(key);
+ return map.get(field);
+ }
+
+ @Override
+ public V getFromMap(String key, K field) {
+ return redissonClient.getMap(key).get(field);
+ }
+
+ public void addToSortedSet(String key, String value) {
+ RSortedSet sortedSet = redissonClient.getSortedSet(key);
+ sortedSet.add(value);
+ }
+
+ @Override
+ public RLock getLock(String key) {
+ return redissonClient.getLock(key);
+ }
+
+ @Override
+ public RLock getFairLock(String key) {
+ return redissonClient.getFairLock(key);
+ }
+
+ @Override
+ public RReadWriteLock getReadWriteLock(String key) {
+ return redissonClient.getReadWriteLock(key);
+ }
+
+ @Override
+ public RSemaphore getSemaphore(String key) {
+ return redissonClient.getSemaphore(key);
+ }
+
+ @Override
+ public RPermitExpirableSemaphore getPermitExpirableSemaphore(String key) {
+ return redissonClient.getPermitExpirableSemaphore(key);
+ }
+
+ @Override
+ public RCountDownLatch getCountDownLatch(String key) {
+ return redissonClient.getCountDownLatch(key);
+ }
+
+ @Override
+ public RBloomFilter getBloomFilter(String key) {
+ return redissonClient.getBloomFilter(key);
+ }
+
+
+}
diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/repository/StrategyRepository.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/repository/StrategyRepository.java
new file mode 100644
index 0000000000000000000000000000000000000000..fc41464014eba7a16b7c29552391b9f1e146df89
--- /dev/null
+++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/repository/StrategyRepository.java
@@ -0,0 +1,84 @@
+package cn.bugstack.infrastructure.persistent.repository;
+
+import cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity;
+import cn.bugstack.domain.strategy.repository.IStrategyRepository;
+import cn.bugstack.infrastructure.persistent.dao.IStrategyAwardDao;
+import cn.bugstack.infrastructure.persistent.po.StrategyAward;
+import cn.bugstack.infrastructure.persistent.redis.IRedisService;
+import cn.bugstack.infrastructure.persistent.redis.RedisService;
+import cn.bugstack.types.common.Constants;
+import lombok.extern.slf4j.Slf4j;
+import org.redisson.misc.Hash;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Repository;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @description: 策略仓储实现
+ * @author: hdr
+ * @PACKAGE_NAME: cn.bugstack.infrastructure.persistent.repository
+ * @DATE: 2024/4/7
+ */
+@Repository
+@Slf4j
+public class StrategyRepository implements IStrategyRepository {
+
+ @Autowired
+ private IStrategyAwardDao strategyAwardDao;
+
+ @Autowired
+ private IRedisService redisService;
+ @Override
+ public List queryStrategyAwardList(Long strategy) {
+ // 1. 查询redis中是否有保存策略数据有的话直接返回
+ String cacheKey = Constants.RedisKey.STRATEGY_AWARD_KEY + strategy;
+ List strategyAwardEntities = redisService.getValue(cacheKey);
+ if (strategyAwardEntities != null && !strategyAwardEntities.isEmpty()) {
+ return strategyAwardEntities;
+ }
+
+ // 2. 没有保存策略数据则查询数据库
+ List strategyAwards = strategyAwardDao.queryStrategyAwardListByStrategyId(strategy);
+ List strategyAwardEntityList = strategyAwards.stream().map(item -> {
+ StrategyAwardEntity strategyAwardEntity = new StrategyAwardEntity();
+ strategyAwardEntity.setStrategyId(item.getStrategyId());
+ strategyAwardEntity.setAwardId(item.getAwardId());
+ strategyAwardEntity.setAwardCount(item.getAwardCount());
+ strategyAwardEntity.setAwardRate(item.getAwardRate());
+ strategyAwardEntity.setAwardCountSurplus(item.getAwardCountSurplus());
+ return strategyAwardEntity;
+ }).collect(Collectors.toList());
+
+ // 2.1 保存到redis中
+ redisService.setValue(cacheKey,strategyAwardEntityList);
+ return strategyAwardEntityList;
+ }
+
+ @Override
+ public void storeStrategyAwardSearchRateTables(Long strategyId, Integer rateRange, HashMap shuffleStrategyAwardSearchRateTables) {
+ // 1. 存储概率值
+ redisService.setValue(Constants.RedisKey.STRATEGY_RATE_RANGE_KEY + strategyId, rateRange.intValue());
+
+ // 2. 存储概率查找表
+ Map cacheRateTable = redisService.getMap(Constants.RedisKey.STRATEGY_RATE_TABLE_KEY + strategyId);
+ cacheRateTable.putAll(shuffleStrategyAwardSearchRateTables);
+ }
+
+ @Override
+ public int getRandomAwardId(Long strategyId) {
+ return redisService.getValue(Constants.RedisKey.STRATEGY_RATE_RANGE_KEY + strategyId);
+ }
+
+ @Override
+ public Integer getStrategyAwardAssemble(Long strategyId, int nextInt) {
+ return redisService.getFromMap(Constants.RedisKey.STRATEGY_RATE_TABLE_KEY + strategyId,nextInt);
+ }
+
+}
diff --git a/xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/common/Constants.java b/xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/common/Constants.java
index 3e21a0d11d286581ba84b5545c78411809a745e9..008bc32b0ba0ae1a280531c7528f15fd4107ef46 100644
--- a/xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/common/Constants.java
+++ b/xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/common/Constants.java
@@ -4,4 +4,11 @@ public class Constants {
public final static String SPLIT = ",";
+ public static class RedisKey {
+ public static String STRATEGY_AWARD_KEY = "big_market_strategy_award_key_";
+ public static String STRATEGY_RATE_TABLE_KEY = "big_market_strategy_rate_table_key_";
+ public static String STRATEGY_RATE_RANGE_KEY = "big_market_strategy_rate_range_key_";
+ }
+
+
}