Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/nuget-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ jobs:
run: dotnet --list-sdks
- name: Check .NET runtimes
run: dotnet --list-runtimes

- name: get version from tag
id: get_version
run: |
realversion="${GITHUB_REF/refs\/tags\//}"
realversion="${realversion//v/}"
echo "VERSION=$realversion" >> $GITHUB_OUTPUT

- name: Update version in csproj
run: |
VERSION=${{ steps.get_version.outputs.VERSION }}
echo "Setting version to $VERSION"

# Update the version in the NRedisStack.csproj file
sed -i "s|<Version>.*</Version>|<Version>$VERSION</Version>|" ./src/NRedisStack/NRedisStack.csproj
sed -i "s|<ReleaseVersion>.*</ReleaseVersion>|<ReleaseVersion>$VERSION</ReleaseVersion>|" ./src/NRedisStack/NRedisStack.csproj
sed -i "s|<PackageVersion>.*</PackageVersion>|<PackageVersion>$VERSION</PackageVersion>|" ./src/NRedisStack/NRedisStack.csproj
cat ./src/NRedisStack/NRedisStack.csproj

- name: Build
run: dotnet pack -c Release --output .
- name: Publish
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ jobs:
- name: .NET Core 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8
dotnet-version: |
6
7
8
- name: Run redis-stack-server docker
working-directory: .github
Expand Down
1 change: 1 addition & 0 deletions src/NRedisStack/Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Pipeline
{
public Pipeline(IDatabase db)
{
db.SetInfoInPipeline();
_batch = db.CreateBatch();
}

Expand Down
39 changes: 25 additions & 14 deletions src/NRedisStack/Search/DataTypes/InfoResult.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
using StackExchange.Redis;
using System.Reflection.Emit;
using StackExchange.Redis;

namespace NRedisStack.Search.DataTypes;

public class InfoResult
{
private readonly Dictionary<string, RedisResult> _all = new();
private static readonly string[] booleanAttributes = { "SORTABLE", "UNF", "NOSTEM", "NOINDEX", "CASESENSITIVE", "WITHSUFFIXTRIE" };
private Dictionary<string, RedisResult>[] _attributes;
private Dictionary<string, RedisResult> _indexOption;
private Dictionary<string, RedisResult> _gcStats;
private Dictionary<string, RedisResult> _cursorStats;

private static readonly string[] booleanAttributes = { "SORTABLE", "UNF", "NOSTEM", "NOINDEX", "CASESENSITIVE", "WITHSUFFIXTRIE", "INDEXEMPTY", "INDEXMISSING" };
public string IndexName => GetString("index_name")!;
public Dictionary<string, RedisResult> IndexOption => GetRedisResultDictionary("index_options")!;
public Dictionary<string, RedisResult>[] Attributes => GetRedisResultDictionaryArray("attributes")!;
public Dictionary<string, RedisResult> IndexOption => _indexOption = _indexOption ?? GetRedisResultDictionary("index_options")!;
public Dictionary<string, RedisResult>[] Attributes => _attributes = _attributes ?? GetAttributesAsDictionaryArray()!;
public long NumDocs => GetLong("num_docs");
public string MaxDocId => GetString("max_doc_id")!;
public long NumTerms => GetLong("num_terms");
Expand Down Expand Up @@ -48,9 +54,9 @@ public class InfoResult
public long NumberOfUses => GetLong("number_of_uses");


public Dictionary<string, RedisResult> GcStats => GetRedisResultDictionary("gc_stats")!;
public Dictionary<string, RedisResult> GcStats => _gcStats = _gcStats ?? GetRedisResultDictionary("gc_stats")!;

public Dictionary<string, RedisResult> CursorStats => GetRedisResultDictionary("cursor_stats")!;
public Dictionary<string, RedisResult> CursorStats => _cursorStats = _cursorStats ?? GetRedisResultDictionary("cursor_stats")!;

public InfoResult(RedisResult result)
{
Expand Down Expand Up @@ -94,24 +100,29 @@ private double GetDouble(string key)
return result;
}

private Dictionary<string, RedisResult>[]? GetRedisResultDictionaryArray(string key)
private Dictionary<string, RedisResult>[]? GetAttributesAsDictionaryArray()
{
if (!_all.TryGetValue(key, out var value)) return default;
if (!_all.TryGetValue("attributes", out var value)) return default;
var values = (RedisResult[])value!;
var result = new Dictionary<string, RedisResult>[values.Length];
for (int i = 0; i < values.Length; i++)
{
var fv = (RedisResult[])values[i]!;
var dict = new Dictionary<string, RedisResult>();
for (int j = 0; j < fv.Length; j += 2)

IEnumerable<RedisResult> enumerable = (RedisResult[])values[i]!;
IEnumerator<RedisResult> results = enumerable.GetEnumerator();
while (results.MoveNext())
{
if (booleanAttributes.Contains((string)fv[j]!))
string attribute = (string)results.Current;
// if its boolean attributes add itself to the dictionary and continue
if (booleanAttributes.Contains(attribute))
{
dict.Add((string)fv[j]!, fv[j--]);
dict.Add(attribute, results.Current);
}
else
{
dict.Add((string)fv[j]!, fv[j + 1]);
{//if its not a boolean attribute, add the next item as value to the dictionary
results.MoveNext(); ;
dict.Add(attribute, results.Current);
}
}
result[i] = dict;
Expand Down
4 changes: 4 additions & 0 deletions src/NRedisStack/Search/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public static Document Load(string id, double score, byte[]? payload, RedisValue
{
Document ret = new Document(id, score, payload);
if (fields == null) return ret;
if (fields.Length == 1 && fields[0].IsNull)
{
return ret;
}
for (int i = 0; i < fields.Length; i += 2)
{
string fieldName = fields[i]!;
Expand Down
16 changes: 8 additions & 8 deletions src/NRedisStack/Search/FieldName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ namespace NRedisStack.Search
{
public class FieldName
{
private readonly string fieldName;
private string? alias;
public string Name { get; }
public string? Alias { get; private set; }

public FieldName(string name) : this(name, null) { }

public FieldName(string name, string? attribute)
{
this.fieldName = name;
this.alias = attribute;
this.Name = name;
this.Alias = attribute;
}

public int AddCommandArguments(List<object> args)
{
args.Add(fieldName);
if (alias == null)
args.Add(Name);
if (Alias is null)
{
return 1;
}

args.Add("AS");
args.Add(alias);
args.Add(Alias);
return 3;
}

Expand All @@ -33,7 +33,7 @@ public static FieldName Of(string name)

public FieldName As(string attribute)
{
this.alias = attribute;
this.Alias = attribute;
return this;
}
}
Expand Down
Loading