Skip to content

Commit 3e0406c

Browse files
Quering string array example added #issue 221 (#231)
1 parent fe83545 commit 3e0406c

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Redis.OM.Modeling;
2+
3+
namespace Redis.OM.QueryingStringsWithinArrays;
4+
5+
[Document(StorageType =StorageType.Json)]
6+
public class Experience
7+
{
8+
[RedisIdField]
9+
[Indexed]
10+
public string Id { get; set; } = default!;
11+
12+
[Indexed]
13+
public string[] Skills { get; set; } = default!;
14+
15+
public override string ToString()
16+
{
17+
return string.Join(" ", Skills);
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Redis.OM.Searching;
2+
3+
namespace Redis.OM.QueryingStringsWithinArrays;
4+
5+
public class Helpers
6+
{
7+
public static async Task AddDummyExperiences(IRedisCollection<Experience> collection)
8+
{
9+
List<Experience> experiences = new()
10+
{
11+
new Experience { Skills = new string[] { "C#", ".NET", "ASP.NET Core" } },
12+
new Experience { Skills = new string[] { "C#", "Android", "MAUI" } },
13+
new Experience { Skills = new string[] { "Java", "JVM", "Spring Boot" } },
14+
new Experience { Skills = new string[] { "Java", "Kotlin", "Android" } },
15+
new Experience { Skills = new string[] { "Dart", "Flutter", "Android" } }
16+
};
17+
foreach (var item in experiences)
18+
{
19+
await collection.InsertAsync(item);
20+
}
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Redis.OM;
2+
using Redis.OM.QueryingStringsWithinArrays;
3+
4+
var provider = new RedisConnectionProvider("redis://localhost:6379");
5+
provider.Connection.CreateIndex(typeof(Experience));
6+
var experiences = provider.RedisCollection<Experience>();
7+
8+
await Helpers.AddDummyExperiences(experiences);
9+
10+
//Contains usage
11+
var filteredExperiences = await experiences.Where(x=>x.Skills.Contains("C#")).ToListAsync();
12+
13+
foreach (var item in filteredExperiences)
14+
{
15+
Console.WriteLine(item.ToString());
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Redis.OM" Version="0.2.3" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.2.32505.173
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Redis.OM.QueryingStringsWithinArrays", "Redis.OM.QueryingStringsWithinArrays.csproj", "{EA6FAC79-A169-4736-8C24-38F74A2D5E44}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{EA6FAC79-A169-4736-8C24-38F74A2D5E44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EA6FAC79-A169-4736-8C24-38F74A2D5E44}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EA6FAC79-A169-4736-8C24-38F74A2D5E44}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EA6FAC79-A169-4736-8C24-38F74A2D5E44}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {80C3C0CF-C83B-4288-8541-981C3025FE75}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)