Skip to content

Commit

Permalink
v1.1.5 -fix: XInfoStream bug #153
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Jun 30, 2023
1 parent 1a7482f commit c4d0910
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/FreeRedis/FreeRedis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>FreeRedis</AssemblyName>
<PackageId>FreeRedis</PackageId>
<RootNamespace>FreeRedis</RootNamespace>
<Version>1.1.4</Version>
<Version>1.1.5</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageProjectUrl>https://github.com/2881099/FreeRedis</PackageProjectUrl>
<Description>FreeRedis is .NET redis client, supports cluster, sentinel, master-slave, pipeline, transaction and connection pool.</Description>
Expand Down
13 changes: 13 additions & 0 deletions src/FreeRedis/Internal/RespHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,19 @@ public static Type GetPropertyOrFieldType(this MemberInfo that)

#region 类型转换
internal static string ToInvariantCultureToString(this object obj) => obj is string objstr ? objstr : string.Format(CultureInfo.InvariantCulture, @"{0}", obj);
public static void MapSetListValue(this object[] list, Dictionary<string, Func<object[], object>> valueHandlers)
{
if (list == null) return;
for (int idx = list.Length - 2, c = 0; idx >= 0 && c < 2; idx -= 2)
{
if (valueHandlers.TryGetValue(list[idx]?.ToString(), out var tryFunc))
{
c++;
var value = list[idx + 1] as object[];
if (value != null) list[idx + 1] = tryFunc(value);
}
}
}
public static T MapToClass<T>(this object[] list, Encoding encoding)
{
if (list == null) return default(T);
Expand Down
57 changes: 26 additions & 31 deletions src/FreeRedis/RedisClient/Streams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,36 +323,36 @@ public static StreamsXInfoStreamResult ThrowOrValueToXInfoStream(this RedisResul
rt.ThrowOrValue((a, _) =>
{
if (a == null) return null;
var objs1 = a[11] as object[];
a[11] = objs1 == null ? null : new StreamsEntry { id = objs1[0].ConvertTo<string>(), fieldValues = objs1[1] as object[] };
var objs2 = a[13] as object[];
a[13] = objs2 == null ? null : new StreamsEntry { id = objs2[0].ConvertTo<string>(), fieldValues = objs2[1] as object[] };
a.MapSetListValue(new Dictionary<string, Func<object[], object>>
{
["first-entry"] = ThrowOrValueToXInfoStreamMapSet,
["last-entry"] = ThrowOrValueToXInfoStreamMapSet
});
return a.MapToClass<StreamsXInfoStreamResult>(rt.Encoding);
});
static object ThrowOrValueToXInfoStreamMapSet(object[] value)
{
var objs1 = value as object[];
return objs1 == null ? null : new StreamsEntry { id = objs1[0].ConvertTo<string>(), fieldValues = objs1[1] as object[] };
}
public static StreamsXInfoStreamFullResult ThrowOrValueToXInfoStreamFullResult(this RedisResult rt) =>
rt.ThrowOrValue((objs_full, _) =>
{
if (objs_full == null) return null;
var objs_entries = objs_full[9] as object[];
if (objs_entries != null)
objs_full.MapSetListValue(new Dictionary<string, Func<object[], object>>
{
objs_full[9] = objs_entries.Select(z =>
["entries"] = value => value.Select(z =>
{
var objs_entry = z as object[];
return objs_entry == null ? null : new StreamsEntry { id = objs_entry[0].ConvertTo<string>(), fieldValues = objs_entry[1] as object[] };
}).ToArray();
}
var objs_groups = objs_full[11] as object[];
if (objs_groups != null)
{
objs_full[11] = objs_groups.Select(z =>
}).ToArray(),
["groups"] = value => value.Select(z =>
{
var objs_group = z as object[];
if (objs_group == null) return null;
var objs_pendings = objs_group[7] as object[];
if (objs_pendings != null)
objs_group.MapSetListValue(new Dictionary<string, Func<object[], object>>
{
objs_group[7] = objs_pendings.Select(y =>
["pending"] = value1 => value1.Select(y =>
{
var objs_pending = y as object[];
if (objs_pending == null) return null;
Expand All @@ -363,19 +363,14 @@ public static StreamsXInfoStreamFullResult ThrowOrValueToXInfoStreamFullResult(t
seen_time = objs_pending[2].ConvertTo<long>(),
pel_count = objs_pending[3].ConvertTo<long>()
};
}).ToArray();
}
var objs_consumers = objs_group[9] as object[];
if (objs_consumers != null)
{
objs_group[9] = objs_consumers.Select(y =>
}).ToArray(),
["consumers"] = value1 => value1.Select(y =>
{
var objs_consumer = y as object[];
if (objs_consumer == null) return null;
var objs_consumer_pendings = objs_consumer[7] as object[];
if (objs_consumer_pendings != null)
objs_consumer.MapSetListValue(new Dictionary<string, Func<object[], object>>
{
objs_consumer[7] = objs_consumer_pendings.Select(x =>
["pending"] = value2 => value2.Select(x =>
{
var objs_consumer_pending = x as object[];
if (objs_consumer_pending == null) return null;
Expand All @@ -386,14 +381,14 @@ public static StreamsXInfoStreamFullResult ThrowOrValueToXInfoStreamFullResult(t
seen_time = objs_consumer_pending[1].ConvertTo<long>(),
pel_count = objs_consumer_pending[2].ConvertTo<long>()
};
}).ToArray();
}
}).ToArray()
});
return objs_consumer.MapToClass<StreamsXInfoStreamFullResult.Group.Consumer>(rt.Encoding);
}).ToArray();
}
}).ToArray()
});
return objs_group.MapToClass<StreamsXInfoStreamFullResult.Group>(rt.Encoding);
}).ToArray();
}
}).ToArray()
});
return objs_full.MapToClass<StreamsXInfoStreamFullResult>(rt.Encoding);
});

Expand Down
2 changes: 1 addition & 1 deletion test/Unit/FreeRedis.Tests/RedisClientTests/PubSubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void PubSubNumSub()
[Fact]
public void PubSubNumPat()
{
cli.PubSubNumPat("123");
cli.PubSubNumPat();
}

[Fact]
Expand Down

0 comments on commit c4d0910

Please sign in to comment.