Conversation
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.Redis.Samples.CosmosDB.Models | ||
| { | ||
| public class StreamData |
There was a problem hiding this comment.
Why is this not a record like PubSubData and RedisData?
| // Helper method to format stream message | ||
| public static StreamData Format(StreamEntry entry, ILogger logger) | ||
| { | ||
| logger.LogInformation("ID: {val}", entry.Id.ToString()); |
There was a problem hiding this comment.
Why are we logging in a Format method? Is this best practice?
| namespace Microsoft.Azure.WebJobs.Extensions.Redis.Samples.CosmosDB.Models | ||
| { | ||
| public record CosmosDBListData( | ||
| string id, |
There was a problem hiding this comment.
These should ideally start with capital letters by convention. This applies to all the models
| Dictionary<string, string> dict = entry.Values.ToDictionary(value => value.Name.ToString(), value => value.Value.ToString()); | ||
|
|
||
| // Create a new list of messages | ||
| var list = new Dictionary<string, Dictionary<string, string>>(); |
There was a problem hiding this comment.
Can simplify to var list = new Dictionary<string, Dictionary<string, string>> { { entry.Id.ToString(), dict } };
| list.Remove(minKey); | ||
| } | ||
|
|
||
| StreamDataSingleDocument data = new StreamDataSingleDocument { id = results.id, maxlen = results.maxlen, messages = list }; |
| // Format the key/value pairs | ||
| foreach (KeyValuePair<string, string> entry in document.values) | ||
| { | ||
| values[i++] = new NameValueEntry(entry.Key, entry.Value); |
There was a problem hiding this comment.
There must be a better way to do this, no?
There was a problem hiding this comment.
Maybe create a list first then convert to array?
| if (cosmosData == null || cosmosData.Count <= 0) return; | ||
|
|
||
| IDatabaseAsync redisDb = s_redisConnection.Value.GetDatabase(); | ||
| //for each item upladed to cosmos, write it to Redis |
|
|
||
| resultsHolder.Add(listEntry); | ||
| CosmosDBListData newEntry = new CosmosDBListData(id: ListKey, value: resultsHolder); | ||
| await db.UpsertItemAsync<CosmosDBListData>(newEntry); |
There was a problem hiding this comment.
Can remove <CosmosDBListData>
| timestamp: DateTime.UtcNow | ||
| ); | ||
|
|
||
| logger.LogInformation($"Key: \"{newKey}\", Value: \"{cosmosDBOut.value}\" addedd to Cosmos DB container: \"{Environment.GetEnvironmentVariable(ContainerSetting.Replace("%",""))}\" at id: \"{cosmosDBOut.id}\""); |
|
|
||
| // Map each key value pair | ||
| Dictionary<string, string> dict = RedisUtilities.StreamEntryToDictionary(entry); | ||
| Dictionary<string, string> dict = entry.Values.ToDictionary(value => value.Name.ToString(), value => value.Value.ToString()); |
There was a problem hiding this comment.
Why are we not using this method anymore?
Updating the samples to be more in line with the rest of the samples.