diff --git a/Splitio.Redis/Services/Cache/Classes/RedisImpressionsCache.cs b/Splitio.Redis/Services/Cache/Classes/RedisImpressionsCache.cs index b5f9990f..503d919e 100644 --- a/Splitio.Redis/Services/Cache/Classes/RedisImpressionsCache.cs +++ b/Splitio.Redis/Services/Cache/Classes/RedisImpressionsCache.cs @@ -1,4 +1,5 @@ using Splitio.Domain; +using Splitio.Redis.Domain; using Splitio.Redis.Services.Cache.Interfaces; using Splitio.Redis.Services.Domain; using Splitio.Services.Shared.Classes; @@ -81,11 +82,7 @@ public async Task RecordImpressionsCountAsync(Dictionary impression // public for tests public RedisValue[] GetImpressions(IList items) { - var impressions = items.Select(item => JsonConvertWrapper.SerializeObjectIgnoreNullValue(new - { - m = new { s = SdkVersion, i = MachineIp, n = MachineName }, - i = new { k = item.keyName, b = item.bucketingKey, f = item.feature, t = item.treatment, r = item.label, c = item.changeNumber, m = item.time, pt = item.previousTime, properties = item.properties } - })); + var impressions = items.Select(item => new RedisKeyImpression(item, SdkVersion, MachineIp, MachineName).ExportJson()); return impressions .Select(i => (RedisValue)i) diff --git a/Splitio.Redis/Services/Domain/RedisKeyImpression.cs b/Splitio.Redis/Services/Domain/RedisKeyImpression.cs new file mode 100644 index 00000000..8c575e40 --- /dev/null +++ b/Splitio.Redis/Services/Domain/RedisKeyImpression.cs @@ -0,0 +1,57 @@ +using Splitio.Domain; +using Splitio.Services.Shared.Classes; + +namespace Splitio.Redis.Domain +{ + public class RedisKeyImpression + { + public RedisKeyImpression(KeyImpression item, string SdkVersion, string MachineIp, string MachineName) + { + this.f = item.feature; + k = item.keyName; + this.t = item.treatment; + this.m = item.time; + this.c = item.changeNumber; + this.r = item.label; + this.b = item.bucketingKey; + this.pt = item.previousTime; + this.properties = item.properties; + this.s = SdkVersion; + this.i = MachineIp; + this.n = MachineName; + } + + public string ExportJson() + { + if (string.IsNullOrEmpty(this.properties)) + { + return JsonConvertWrapper.SerializeObject(new + { + m = new { s = this.s, i = this.i, n = this.n }, + i = new { k = this.k, b = this.b, f = this.f, t = this.t, r = this.r, c = this.c, m = this.m, pt = this.pt } + }); + } else { + return JsonConvertWrapper.SerializeObject(new + { + m = new { s = this.s, i = this.i, n = this.n }, + i = new { k = this.k, b = this.b, f = this.f, t = this.t, r = this.r, c = this.c, m = this.m, pt = this.pt, properties = this.properties } + }); + } + } + + public string f { get; set; } + public string k { get; set; } + public string t { get; set; } + public long m { get; set; } + public long? c { get; set; } + public string r { get; set; } + public string b { get; set; } + public long? pt { get; set; } + public string properties { get; set; } + + public string s { get; set; } + public string i { get; set; } + public string n { get; set; } + + } +} diff --git a/Splitio.Redis/Splitio.Redis.csproj b/Splitio.Redis/Splitio.Redis.csproj index ed6c646d..68bc87e5 100644 --- a/Splitio.Redis/Splitio.Redis.csproj +++ b/Splitio.Redis/Splitio.Redis.csproj @@ -7,7 +7,7 @@ false false false - 7.13.0-rc2 + 7.13.0-rc4 true SplitioRedis.snk Apache-2.0 diff --git a/src/Splitio/Splitio.csproj b/src/Splitio/Splitio.csproj index 8f059f77..cf481d2a 100644 --- a/src/Splitio/Splitio.csproj +++ b/src/Splitio/Splitio.csproj @@ -7,7 +7,7 @@ false false false - 7.13.0-rc2 + 7.13.0-rc4 Splitio true Splitio.snk diff --git a/tests/Splitio-tests/Unit Tests/Impressions/RedisImpressionsCacheTests.cs b/tests/Splitio-tests/Unit Tests/Impressions/RedisImpressionsCacheTests.cs index b1addd5c..4d84d7d6 100644 --- a/tests/Splitio-tests/Unit Tests/Impressions/RedisImpressionsCacheTests.cs +++ b/tests/Splitio-tests/Unit Tests/Impressions/RedisImpressionsCacheTests.cs @@ -107,9 +107,9 @@ public void CorrectFormatStoreImpressions() // Act. var result = _cache.GetImpressions(impressions); - var impression1 = "{\"m\":{\"s\":\"version\",\"i\":\"ip\",\"n\":\"mm\"},\"i\":{\"k\":\"matching-key\",\"b\":\"bucketing-key\",\"f\":\"feature-1\",\"t\":\"treatment\",\"r\":\"label\",\"c\":3333444,\"m\":34534546}}"; + var impression1 = "{\"m\":{\"s\":\"version\",\"i\":\"ip\",\"n\":\"mm\"},\"i\":{\"k\":\"matching-key\",\"b\":\"bucketing-key\",\"f\":\"feature-1\",\"t\":\"treatment\",\"r\":\"label\",\"c\":3333444,\"m\":34534546,\"pt\":null}}"; var impression2 = "{\"m\":{\"s\":\"version\",\"i\":\"ip\",\"n\":\"mm\"},\"i\":{\"k\":\"matching-key\",\"b\":\"bucketing-key\",\"f\":\"feature-1\",\"t\":\"treatment\",\"r\":\"label\",\"c\":3333444,\"m\":34534550,\"pt\":34534546}}"; - var impression3 = "{\"m\":{\"s\":\"version\",\"i\":\"ip\",\"n\":\"mm\"},\"i\":{\"k\":\"matching-key\",\"b\":\"bucketing-key\",\"f\":\"feature-2\",\"t\":\"treatment\",\"r\":\"label\",\"c\":3333444,\"m\":34534546,\"properties\":\"{\\\"prop\\\":\\\"val\\\"}\"}}"; + var impression3 = "{\"m\":{\"s\":\"version\",\"i\":\"ip\",\"n\":\"mm\"},\"i\":{\"k\":\"matching-key\",\"b\":\"bucketing-key\",\"f\":\"feature-2\",\"t\":\"treatment\",\"r\":\"label\",\"c\":3333444,\"m\":34534546,\"pt\":null,\"properties\":\"{\\\"prop\\\":\\\"val\\\"}\"}}"; // Assert. Assert.AreEqual(impression1, result[0].ToString());