@@ -88,8 +88,10 @@ class UpstashRedisBackedChatMemory_Memory implements INode {
88
88
89
89
const initalizeUpstashRedis = async ( nodeData : INodeData , options : ICommonObject ) : Promise < BufferMemory > => {
90
90
const baseURL = nodeData . inputs ?. baseURL as string
91
- const sessionTTL = nodeData . inputs ?. sessionTTL as string
92
91
const sessionId = nodeData . inputs ?. sessionId as string
92
+ const _sessionTTL = nodeData . inputs ?. sessionTTL as string
93
+
94
+ const sessionTTL = _sessionTTL ? parseInt ( _sessionTTL , 10 ) : undefined
93
95
94
96
const credentialData = await getCredentialData ( nodeData . credential ?? '' , options )
95
97
const upstashRestToken = getCredentialParam ( 'upstashRestToken' , credentialData , nodeData )
@@ -101,14 +103,15 @@ const initalizeUpstashRedis = async (nodeData: INodeData, options: ICommonObject
101
103
102
104
const redisChatMessageHistory = new UpstashRedisChatMessageHistory ( {
103
105
sessionId,
104
- sessionTTL : sessionTTL ? parseInt ( sessionTTL , 10 ) : undefined ,
106
+ sessionTTL,
105
107
client
106
108
} )
107
109
108
110
const memory = new BufferMemoryExtended ( {
109
111
memoryKey : 'chat_history' ,
110
112
chatHistory : redisChatMessageHistory ,
111
113
sessionId,
114
+ sessionTTL,
112
115
redisClient : client
113
116
} )
114
117
@@ -118,16 +121,19 @@ const initalizeUpstashRedis = async (nodeData: INodeData, options: ICommonObject
118
121
interface BufferMemoryExtendedInput {
119
122
redisClient : Redis
120
123
sessionId : string
124
+ sessionTTL ?: number
121
125
}
122
126
123
127
class BufferMemoryExtended extends FlowiseMemory implements MemoryMethods {
124
128
sessionId = ''
125
129
redisClient : Redis
130
+ sessionTTL ?: number
126
131
127
132
constructor ( fields : BufferMemoryInput & BufferMemoryExtendedInput ) {
128
133
super ( fields )
129
134
this . sessionId = fields . sessionId
130
135
this . redisClient = fields . redisClient
136
+ this . sessionTTL = fields . sessionTTL
131
137
}
132
138
133
139
async getChatMessages ( overrideSessionId = '' , returnBaseMessages = false ) : Promise < IMessage [ ] | BaseMessage [ ] > {
@@ -152,12 +158,14 @@ class BufferMemoryExtended extends FlowiseMemory implements MemoryMethods {
152
158
const newInputMessage = new HumanMessage ( input . text )
153
159
const messageToAdd = [ newInputMessage ] . map ( ( msg ) => msg . toDict ( ) )
154
160
await this . redisClient . lpush ( id , JSON . stringify ( messageToAdd [ 0 ] ) )
161
+ if ( this . sessionTTL ) await this . redisClient . expire ( id , this . sessionTTL )
155
162
}
156
163
157
164
if ( output ) {
158
165
const newOutputMessage = new AIMessage ( output . text )
159
166
const messageToAdd = [ newOutputMessage ] . map ( ( msg ) => msg . toDict ( ) )
160
167
await this . redisClient . lpush ( id , JSON . stringify ( messageToAdd [ 0 ] ) )
168
+ if ( this . sessionTTL ) await this . redisClient . expire ( id , this . sessionTTL )
161
169
}
162
170
}
163
171
0 commit comments