-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add redis playground as well as launchsettings.json
- Loading branch information
Showing
12 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RedisPlayground", "RedisPlayground\RedisPlayground.csproj", "{20A28F41-5F94-4030-B2B2-2E4AB2243DB2}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{20A28F41-5F94-4030-B2B2-2E4AB2243DB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{20A28F41-5F94-4030-B2B2-2E4AB2243DB2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{20A28F41-5F94-4030-B2B2-2E4AB2243DB2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{20A28F41-5F94-4030-B2B2-2E4AB2243DB2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.IO.Compression; | ||
using System.Text; | ||
|
||
namespace RedisPlayground; | ||
|
||
public static class Extensions | ||
{ | ||
public static string Decompress(string s) | ||
{ | ||
var bytes = Convert.FromBase64String(s); | ||
using var memoryStreamInput = new MemoryStream(bytes); | ||
using var memoryStreamOutput = new MemoryStream(); | ||
using var gzipStream = new GZipStream(memoryStreamInput, CompressionMode.Decompress); | ||
gzipStream.CopyTo(memoryStreamOutput); | ||
return Encoding.Unicode.GetString(memoryStreamOutput.ToArray()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
Azure/RedisPlayground/RedisPlayground/Models/AccountLoanSummary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RedisPlayground.Models; | ||
|
||
public class AccountLoanSummary | ||
{ | ||
public decimal? PrincipalAmount { get; set; } | ||
public decimal? InterestAmount { get; set; } | ||
public decimal? TotalLateFeeAmount { get; set; } | ||
public decimal? TotalNSFFeeAmount { get; set; } | ||
public decimal? PerDiem { get; set; } | ||
public decimal? PayOffAmount { get; set; } | ||
public decimal? APRRate { get; set; } | ||
public DateTime? CurrentMaturityDate { get; set; } | ||
public int? NumberOfPaymentsRemaining { get; set; } | ||
public decimal? InsuranceAmountDelinquent { get; set; } | ||
public DateTime? PastDueSinceDate { get; set; } | ||
public decimal? AmountToRoll { get; set; } | ||
public int? NumberOfPaymentsMade { get; set; } | ||
public DateTime? NextPaymentDueDate { get; set; } | ||
public decimal? PastDueAmount { get; set; } | ||
public int NumberOfDaysPastDue { get; set; } | ||
public decimal TotalAmountDue { get; set; } | ||
public decimal NextAmountDue { get; set; } | ||
public decimal AmountDueNow { get; set; } | ||
public DateTime? StatusChangeEffectiveDate { get; set; } | ||
public int? StatusReasonCode { get; set; } | ||
public string StatusReasonDescription { get; set; } | ||
public string ReportLot { get; set; } | ||
public DateTime? SaleDate { get; set; } | ||
public decimal? PaymentAmount { get; set; } | ||
public decimal? OriginalLoanBalance { get; set; } | ||
public short? TotalNumberOfPayments { get; set; } | ||
[JsonConverter(typeof(NullConverter))] | ||
public short? PaymentDueDayOne { get; set; } | ||
[JsonConverter(typeof(NullConverter))] | ||
public short? PaymentDueDayTwo { get; set; } | ||
public DateTime? OriginalMaturityDate { get; set; } | ||
public string PaymentFrequencyName { get; set; } | ||
public decimal? OriginalAPR { get; set; } | ||
public char AccountStatusKey { get; set; } | ||
public bool IsDisplayReason { get; set; } | ||
public int CurrentPoolNumber { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
using RedisPlayground; | ||
|
||
|
||
// var devRedisHost = "localhost"; | ||
// var devRedisPort = 6380; | ||
// var devRedisConnection = "localhost:6379"; | ||
// var devRedisConnection = ""; | ||
var testRedisConnection = ""; | ||
var testRedisHost = ""; | ||
|
||
var redisExtensions = new RedisExtensions(testRedisConnection, testRedisHost); | ||
|
||
var keys = TimerExtensions.TimeIt(redisExtensions.GetAllKeys); | ||
var results = await TimerExtensions.TimeItAsync(() => redisExtensions.GetAllRecords(keys)); | ||
|
||
Console.WriteLine($"Got back {results.Count} results"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Newtonsoft.Json; | ||
using RedisPlayground.Models; | ||
using StackExchange.Redis; | ||
|
||
namespace RedisPlayground; | ||
|
||
public class RedisExtensions | ||
{ | ||
private readonly ConnectionMultiplexer _redis; | ||
private readonly string _redisHost; | ||
|
||
public RedisExtensions(string redisConnection, string redisHost) | ||
{ | ||
Console.WriteLine($"host: {redisHost}: connecting to {redisConnection}"); | ||
_redisHost = redisHost; | ||
_redis = ConnectionMultiplexer.Connect(redisConnection); | ||
} | ||
|
||
public List<string> GetAllKeys() | ||
{ | ||
var listKeys = new List<string>(); | ||
var keys = _redis.GetServer(_redisHost, 6380).Keys(pattern: "AccountLoanSummary").ToList(); | ||
listKeys.AddRange(keys.Select(key => (string) key).ToList()); | ||
return listKeys; | ||
} | ||
|
||
public async Task<List<AccountLoanSummary>> GetAllRecords(List<string> keys) | ||
{ | ||
var db = _redis.GetDatabase(); | ||
var results = new List<AccountLoanSummary>(); | ||
var totalKeys = keys.Count; | ||
var count = 1; | ||
var errorCount = 0; | ||
foreach (var key in keys) | ||
{ | ||
var redisValue = (await db.StringGetAsync(key)).ToString(); | ||
// var accountLoanSummary = new AccountLoanSummary | ||
// { | ||
// | ||
// } | ||
try | ||
{ | ||
var decompressedResult = Extensions.Decompress(redisValue); | ||
var result = JsonConvert.DeserializeObject<AccountLoanSummary>(decompressedResult); | ||
|
||
results.Add(result); | ||
Console.WriteLine($"Grabbed {count}/{totalKeys} - {errorCount}"); | ||
count++; | ||
} | ||
catch (Exception ex) | ||
{ | ||
errorCount++; | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
} | ||
|
||
public class NullConverter: JsonConverter | ||
{ | ||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) | ||
{ | ||
return existingValue; | ||
} | ||
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Azure/RedisPlayground/RedisPlayground/RedisPlayground.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<PackageReference Include="StackExchange.Redis" Version="2.6.70" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Diagnostics; | ||
|
||
namespace RedisPlayground; | ||
|
||
public static class TimerExtensions | ||
{ | ||
public static TOutput TimeIt<TOutput>(Func<TOutput> func) | ||
{ | ||
var stopwatch = Stopwatch.StartNew(); | ||
var output = func(); | ||
stopwatch.Stop(); | ||
var ts = stopwatch.Elapsed; | ||
Console.WriteLine($"Took: {ts.Minutes}Minutes, {ts.Seconds} seconds to execute"); | ||
return output; | ||
} | ||
|
||
public static async Task<List<TOutput>> TimeItAsync<TOutput>(Func<Task<List<TOutput>>> func) | ||
{ | ||
var stopwatch = Stopwatch.StartNew(); | ||
var output = await func(); | ||
stopwatch.Stop(); | ||
var ts = stopwatch.Elapsed; | ||
Console.WriteLine($"Took: {ts.Minutes}Minutes, {ts.Seconds} seconds to execute"); | ||
return output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:53626", | ||
"sslPort": 44318 | ||
} | ||
}, | ||
"profiles": { | ||
"ServiceBusExample": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7152;http://localhost:5260", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"profiles": { | ||
"WeatherDataProcessor": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--port 7076", | ||
"launchBrowser": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:61702", | ||
"sslPort": 44373 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:5236", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "https://localhost:7199;http://localhost:5236", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
SingleOrDefaultVsFirstOrDefaultBenchmarks/FirstOrDefaultVsSingleOrDefault/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
Console.WriteLine("Hello, World!"); |