From 6de65b56a055d120a3a1463bf1b32ea9d86996a8 Mon Sep 17 00:00:00 2001 From: Michael Landis Date: Mon, 10 Oct 2022 10:34:25 -0700 Subject: [PATCH] chore: update examples to release 0.37.0 (#292) Update the examples to SDK release version 0.37.0. --- .../MomentoApplication.csproj | 2 +- examples/MomentoApplication/Program.cs | 20 ++++++++++++------- .../MomentoFSharpApplication.fsproj | 2 +- examples/MomentoFSharpApplication/Program.fs | 4 ++-- examples/MomentoLoadGen/MomentoLoadGen.csproj | 2 +- examples/MomentoLoadGen/Program.cs | 2 +- examples/MomentoUsage/MomentoUsage.csproj | 2 +- examples/MomentoUsage/Program.cs | 14 ++++++++----- 8 files changed, 29 insertions(+), 19 deletions(-) diff --git a/examples/MomentoApplication/MomentoApplication.csproj b/examples/MomentoApplication/MomentoApplication.csproj index 7e99bfac..dae474bb 100644 --- a/examples/MomentoApplication/MomentoApplication.csproj +++ b/examples/MomentoApplication/MomentoApplication.csproj @@ -9,7 +9,7 @@ - + diff --git a/examples/MomentoApplication/Program.cs b/examples/MomentoApplication/Program.cs index efe167e5..8bcd64ba 100644 --- a/examples/MomentoApplication/Program.cs +++ b/examples/MomentoApplication/Program.cs @@ -11,9 +11,9 @@ const string CACHE_NAME = "momento-example"; const string KEY = "MyKey"; const string VALUE = "MyData"; -const uint DEFAULT_TTL_SECONDS = 60; +TimeSpan DEFAULT_TTL = TimeSpan.FromSeconds(60); -using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest(), authProvider, DEFAULT_TTL_SECONDS)) +using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest(), authProvider, DEFAULT_TTL)) { Console.WriteLine($"Creating cache {CACHE_NAME}"); var createCacheResponse = await client.CreateCacheAsync(CACHE_NAME); @@ -23,7 +23,8 @@ if (createCacheError.ErrorCode == MomentoErrorCode.LIMIT_EXCEEDED_ERROR) { Console.WriteLine("Error: cache limit exceeded. We need to talk to support@moentohq.com! Exiting."); - } else + } + else { Console.WriteLine($"Error creating cache: {createCacheError.Message}. Exiting."); } @@ -48,7 +49,8 @@ Console.WriteLine($"- {cacheInfo.Name}"); } token = listCachesSuccess.NextPageToken; - } else if (listCachesResponse is ListCachesResponse.Error listCachesError) + } + else if (listCachesResponse is ListCachesResponse.Error listCachesError) { // We do not consider this a fatal error, so we just report it. Console.WriteLine($"Error listing caches: {listCachesError.Message}"); @@ -70,18 +72,22 @@ if (getResponse is CacheGetResponse.Hit getHit) { Console.WriteLine($"Looked up value: {getHit.ValueString}, Stored value: {VALUE}"); - } else if (getResponse is CacheGetResponse.Miss) + } + else if (getResponse is CacheGetResponse.Miss) { // This shouldn't be fatal but should be reported. Console.WriteLine($"Error: got a cache miss for {KEY}!"); - } else if (getResponse is CacheGetResponse.Error getError) { + } + else if (getResponse is CacheGetResponse.Error getError) + { // Also not considered fatal. Console.WriteLine($"Error getting value: {getError.Message}!"); } Console.WriteLine($"\nDeleting key {KEY}"); var deleteKeyResponse = await client.DeleteAsync(CACHE_NAME, KEY); - if (deleteKeyResponse is CacheDeleteResponse.Error deleteKeyError) { + if (deleteKeyResponse is CacheDeleteResponse.Error deleteKeyError) + { // Also not considred fatal. Console.WriteLine($"Error deleting key: {deleteKeyError.Message}!"); } diff --git a/examples/MomentoFSharpApplication/MomentoFSharpApplication.fsproj b/examples/MomentoFSharpApplication/MomentoFSharpApplication.fsproj index b06feca3..a20db6c3 100644 --- a/examples/MomentoFSharpApplication/MomentoFSharpApplication.fsproj +++ b/examples/MomentoFSharpApplication/MomentoFSharpApplication.fsproj @@ -10,7 +10,7 @@ - + diff --git a/examples/MomentoFSharpApplication/Program.fs b/examples/MomentoFSharpApplication/Program.fs index c56ddde0..811e9f02 100644 --- a/examples/MomentoFSharpApplication/Program.fs +++ b/examples/MomentoFSharpApplication/Program.fs @@ -5,12 +5,12 @@ open Momento.Sdk.Responses open System let CACHE_NAME = "cache" -let DEFAULT_TTL_SECONDS = 60u +let DEFAULT_TTL = TimeSpan.FromSeconds(60) let authProvider = new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN") let exerciseCache() = ( printfn "Howdy" - using(new SimpleCacheClient(Configurations.Laptop.Latest(), authProvider, DEFAULT_TTL_SECONDS)) (fun client -> + using(new SimpleCacheClient(Configurations.Laptop.Latest(), authProvider, DEFAULT_TTL)) (fun client -> let createCacheResult = client.CreateCacheAsync(CACHE_NAME) |> Async.AwaitTask printfn("Listing caches:") diff --git a/examples/MomentoLoadGen/MomentoLoadGen.csproj b/examples/MomentoLoadGen/MomentoLoadGen.csproj index 15223837..2fc7a5cc 100644 --- a/examples/MomentoLoadGen/MomentoLoadGen.csproj +++ b/examples/MomentoLoadGen/MomentoLoadGen.csproj @@ -22,7 +22,7 @@ - + diff --git a/examples/MomentoLoadGen/Program.cs b/examples/MomentoLoadGen/Program.cs index e5935e98..4d9636a1 100644 --- a/examples/MomentoLoadGen/Program.cs +++ b/examples/MomentoLoadGen/Program.cs @@ -94,7 +94,7 @@ public async Task Run() using (var momento = new SimpleCacheClient( _momentoClientConfig, authProvider, - CACHE_ITEM_TTL_SECONDS + TimeSpan.FromSeconds(CACHE_ITEM_TTL_SECONDS) )) { try diff --git a/examples/MomentoUsage/MomentoUsage.csproj b/examples/MomentoUsage/MomentoUsage.csproj index 29d122c9..e2864f31 100644 --- a/examples/MomentoUsage/MomentoUsage.csproj +++ b/examples/MomentoUsage/MomentoUsage.csproj @@ -11,6 +11,6 @@ - + diff --git a/examples/MomentoUsage/Program.cs b/examples/MomentoUsage/Program.cs index 63bb7c35..6c2b9a85 100644 --- a/examples/MomentoUsage/Program.cs +++ b/examples/MomentoUsage/Program.cs @@ -8,19 +8,21 @@ const string CACHE_NAME = "cache"; const string KEY = "MyKey"; const string VALUE = "MyData"; -const uint DEFAULT_TTL_SECONDS = 60; +TimeSpan DEFAULT_TTL = TimeSpan.FromSeconds(60); -using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest(), authProvider, DEFAULT_TTL_SECONDS)) +using (SimpleCacheClient client = new SimpleCacheClient(Configurations.Laptop.Latest(), authProvider, DEFAULT_TTL)) { var createCacheResponse = await client.CreateCacheAsync(CACHE_NAME); - if (createCacheResponse is CreateCacheResponse.Error createError) { + if (createCacheResponse is CreateCacheResponse.Error createError) + { Console.WriteLine($"Error creating cache: {createError.Message}. Exiting."); Environment.Exit(1); } Console.WriteLine($"Setting key: {KEY} with value: {VALUE}"); var setResponse = await client.SetAsync(CACHE_NAME, KEY, VALUE); - if (setResponse is CacheSetResponse.Error setError) { + if (setResponse is CacheSetResponse.Error setError) + { Console.WriteLine($"Error setting value: {setError.Message}. Exiting."); Environment.Exit(1); } @@ -30,7 +32,9 @@ if (getResponse is CacheGetResponse.Hit hitResponse) { Console.WriteLine($"Looked up value: {hitResponse.ValueString}, Stored value: {VALUE}"); - } else if (getResponse is CacheGetResponse.Error getError) { + } + else if (getResponse is CacheGetResponse.Error getError) + { Console.WriteLine($"Error getting value: {getError.Message}"); } }