Unverified Commit 026476df authored by Marc Gravell's avatar Marc Gravell Committed by GitHub

API proposal for #1359 (#1361)

parent fba49c53
namespace StackExchange.Redis
using System;
namespace StackExchange.Redis
{
/// <summary>
/// Describes an entry contained in a Redis Stream.
......@@ -26,6 +28,26 @@ internal StreamEntry(RedisValue id, NameValueEntry[] values)
/// </summary>
public NameValueEntry[] Values { get; }
/// <summary>
/// Search for a specific field by name, returning the value
/// </summary>
public RedisValue this[RedisValue fieldName]
{
get
{
var values = Values;
if (values != null)
{
for (int i = 0; i < values.Length; i++)
{
if (values[i].name == fieldName)
return values[i].value;
}
}
return RedisValue.Null;
}
}
/// <summary>
/// Indicates that the Redis Stream Entry is null.
/// </summary>
......
using System;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;
......@@ -1784,5 +1785,34 @@ public void StreamReadGroupMultiStreamWithNoAckShowsNoPendingMessages()
}
private RedisKey GetUniqueKey(string type) => $"{type}_stream_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}";
[Fact]
public async Task StreamReadIndexerUsage()
{
var streamName = GetUniqueKey("read-group-indexer");
using (var conn = Create())
{
Skip.IfMissingFeature(conn, nameof(RedisFeatures.Streams), r => r.Streams);
var db = conn.GetDatabase();
await db.StreamAddAsync(streamName, new[] {
new NameValueEntry("x", "blah"),
new NameValueEntry("msg", @"{""name"":""test"",""id"":123}"),
new NameValueEntry("y", "more blah"),
});
var streamResult = await db.StreamRangeAsync(streamName, count: 1000);
var evntJson = streamResult
.Select(x => (dynamic)JsonConvert.DeserializeObject(x["msg"]))
.ToList();
var obj = Assert.Single(evntJson);
Assert.Equal(123, (int)obj.id);
Assert.Equal("test", (string)obj.name);
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment