Skip to content

Commit ac97a5f

Browse files
zhilingluoCopilot
andauthored
Update src/agentscope_runtime/engine/services/memory/redis_memory_service.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0139e5c commit ac97a5f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/agentscope_runtime/engine/services/memory/redis_memory_service.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,17 @@ async def search_memory(
185185

186186
# Apply top_k filter if specified
187187
if top_k is not None:
188-
return matched_messages[-top_k:]
188+
result = matched_messages[-top_k:]
189+
else:
190+
result = matched_messages
189191

190-
return matched_messages
192+
# Refresh TTL on read to extend lifetime of actively used data,
193+
# if a TTL is configured and there is existing data for this key.
194+
ttl_seconds = getattr(self, "_ttl", None)
195+
if ttl_seconds and hash_keys:
196+
await self._redis.expire(key, ttl_seconds)
191197

198+
return result
192199
async def get_query_text(self, message: Message) -> str:
193200
if message:
194201
if message.type == MessageType.MESSAGE:

0 commit comments

Comments
 (0)