Skip to content

Commit

Permalink
Merge pull request #531 from momentohq/example-set-sample
Browse files Browse the repository at this point in the history
chore: add docs example for SetSample
  • Loading branch information
cprice404 authored Feb 8, 2024
2 parents 8c5e7df + 5ffae9d commit 7cbcf27
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/DictionaryExample/DictionaryExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Momento.Sdk" Version="1.19.0" />
<PackageReference Include="Momento.Sdk" Version="1.30.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion examples/DisposableTokens/DisposableTokens.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Momento.Sdk" Version="1.20.0" />
<PackageReference Include="Momento.Sdk" Version="1.30.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion examples/DocExampleApis/DocExampleApis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Momento.Sdk" Version="1.21.2" />
<PackageReference Include="Momento.Sdk" Version="1.30.1" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions examples/DocExampleApis/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static async Task Main(string[] args)
await Example_API_Get(client);
await Example_API_Delete(client);

await Example_API_SetSample(client);

await Example_API_GenerateDisposableToken(authClient);

await Example_API_InstantiateTopicClient();
Expand Down Expand Up @@ -138,6 +140,29 @@ public static async Task Example_API_Delete(CacheClient cacheClient)
}
}

public static async Task Example_API_SetSample(CacheClient cacheClient)
{
var setAddResult = await cacheClient.SetAddElementsAsync("test-cache", "test-set", new string[] {"foo", "bar", "baz"});
if (setAddResult is CacheSetAddElementsResponse.Success)
{
Console.WriteLine("Added elements to 'test-set' successfully");
}
else if (setAddResult is CacheSetAddElementsResponse.Error error)
{
throw new Exception($"An error occurred while attempting to delete key 'test-key' from cache 'test-cache': {error.ErrorCode}: {error}");
}

var setSampleResult = await cacheClient.SetSampleAsync("test-cache", "test-set", 2);
if (setSampleResult is CacheSetSampleResponse.Hit setSampleHit)
{
Console.WriteLine($"Sampled random elements from 'test-set': {String.Join(", ", setSampleHit.ValueSetString)}");
}
else if (setSampleResult is CacheSetSampleResponse.Error error)
{
throw new Exception($"An error occurred while attempting to sample from 'test-set' from cache 'test-cache': {error.ErrorCode}: {error}");
}
}

public static async Task Example_API_GenerateDisposableToken(IAuthClient authClient)
{
// Generate a disposable token with read-write access to a specific key in one cache
Expand Down
2 changes: 1 addition & 1 deletion examples/MomentoApplication/MomentoApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Momento.Sdk" Version="1.19.0" />
<PackageReference Include="Momento.Sdk" Version="1.30.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Momento.Sdk" Version="1.19.0" />
<PackageReference Include="Momento.Sdk" Version="1.30.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion examples/MomentoLoadGen/MomentoLoadGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Momento.Sdk" Version="1.19.0" />
<PackageReference Include="Momento.Sdk" Version="1.30.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion examples/MomentoUsage/MomentoUsage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Momento.Sdk" Version="1.19.0" />
<PackageReference Include="Momento.Sdk" Version="1.30.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion examples/TopicExample/TopicExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Momento.Sdk" Version="1.19.0" />
<PackageReference Include="Momento.Sdk" Version="1.30.1" />
</ItemGroup>
</Project>

0 comments on commit 7cbcf27

Please sign in to comment.