You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingSystem.Diagnostics.CodeAnalysis;usingSystem.Text.Json;usingLangChain.Memory;usingLangChain.Providers;usingStackExchange.Redis;namespaceLangChain.Databases;/// <summary>/// Chat message history stored in a Redis database./// </summary>[RequiresDynamicCode("Requires dynamic code.")][RequiresUnreferencedCode("Requires unreferenced code.")]publicclassRedisChatMessageHistory:BaseChatMessageHistory{publicTimeSpan?Ttl{get;set;}privatereadonlystring_sessionId;privatereadonlystring_keyPrefix;privatereadonlyLazy<ConnectionMultiplexer>_multiplexer;/// <inheritdoc />publicRedisChatMessageHistory(stringsessionId,stringconnectionString,stringkeyPrefix="message_store:",TimeSpan?ttl=null){_sessionId=sessionId;_keyPrefix=keyPrefix;Ttl=ttl;_multiplexer=newLazy<ConnectionMultiplexer>(()=>{varmultiplexer=ConnectionMultiplexer.Connect(connectionString);returnmultiplexer;},LazyThreadSafetyMode.ExecutionAndPublication);}/// <summary>/// Construct the record key to use/// </summary>privatestringKey=>_keyPrefix+_sessionId;/// <summary>/// Retrieve the messages from Redis/// TODO: use async methods/// </summary>publicoverrideIReadOnlyList<Message>Messages{get{vardatabase=_multiplexer.Value.GetDatabase();varvalues=database.ListRange(Key,start:0,stop:-1);varmessages=values.Select(v =>JsonSerializer.Deserialize<Message>(v.ToString())).Reverse();returnmessages.ToList();}}/// <summary>/// Append the message to the record in Redis/// </summary>publicoverrideasyncTaskAddMessage(Messagemessage){vardatabase=_multiplexer.Value.GetDatabase();awaitdatabase.ListLeftPushAsync(Key,JsonSerializer.Serialize(message)).ConfigureAwait(false);if(Ttl.HasValue){awaitdatabase.KeyExpireAsync(Key,Ttl).ConfigureAwait(false);}}/// <summary>/// Clear session memory from Redis/// </summary>publicoverrideasyncTaskClear(){vardatabase=_multiplexer.Value.GetDatabase();awaitdatabase.KeyDeleteAsync(Key).ConfigureAwait(false);}}
The text was updated successfully, but these errors were encountered:
/ </summary>
/ Append the message to the record in Redis
/ </summary>
/ Clear session memory from Redis
/ </summary>
LangChain.Databases/src/Redis/src/RedisChatMessageHistory.cs
Line 50 in f753e0c
The text was updated successfully, but these errors were encountered: