使用container_name做redis key前缀

This commit is contained in:
zhangkun9038@dingtalk.com 2025-08-23 12:12:03 +08:00
parent 903919cdee
commit 533fa03492

View File

@ -943,8 +943,12 @@ class FreqaiPrimer(IStrategy):
current_mode = self.config.get('runmode')
if current_mode == RunMode.LIVE:
try:
# 获取主机名
hostname = socket.gethostname()
# 获取容器名称和环境变量
container_name = os.getenv('CONTAINER_NAME', socket.gethostname())
# 获取进程启动时间戳(全局有效)
if not hasattr(self, '_start_timestamp'):
self._start_timestamp = int(time.time() * 1000)
# 将币对名从BTC/USDT格式转换为BTC-USDT格式
pair_redis = pair.replace('/', '-')
@ -952,8 +956,8 @@ class FreqaiPrimer(IStrategy):
# 获取当前时间戳(毫秒)
timestamp_ms = int(time.time() * 1000)
# 构建Redis key: ${主机名}_${币对名}_entry_${时间戳}
redis_key = f"{hostname}_{pair_redis}_entry_{timestamp_ms}"
# 构建Redis key: ${CONTAINER_NAME}_{startTimeStamp}_{币对名}_entry_{时间戳}
redis_key = f"{container_name}_{self._start_timestamp}_{pair_redis}_entry_{timestamp_ms}"
# 获取Redis客户端
redis_client = self._get_redis_client()
@ -978,7 +982,7 @@ class FreqaiPrimer(IStrategy):
'market_regime': str(market_regime),
'timestamp': timestamp_ms,
'pair': str(pair),
'hostname': str(hostname),
'hostname': str(container_name),
'immediate_entry': bool(dataframe.loc[last_idx, 'immediate_entry']) if 'immediate_entry' in dataframe.columns else False,
'conditions_analysis': {
'total_conditions': len(conditions_summary),