From 06eb6f8241f8bcd9f3af2638e81d51a509ef9045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulus=20P=C3=A4rssinen?= Date: Tue, 23 Apr 2024 22:52:57 +0300 Subject: [PATCH] Apply IDE0300 & IDE0028 on Garnet.test (#295) * Apply IDE0300 to Garnet.test: Collection initialization can be simplified * Apply IDE0028 to Garnet.test: Collection initialization can be simplified * Simplify GetSigned in GarnetBitmapTests * This table is unnecessary * Also it resulted the dotnet format bug * dotnet format --------- Co-authored-by: Tal Zaccai --- test/Garnet.test/CacheSizeTrackerTests.cs | 6 +- test/Garnet.test/GarnetBitmapTests.cs | 50 +++++------ test/Garnet.test/GarnetClientTests.cs | 19 ++--- test/Garnet.test/GarnetObjectTests.cs | 4 +- test/Garnet.test/GarnetServerConfigTests.cs | 12 +-- test/Garnet.test/HyperLogLogTests.cs | 76 ++++++++--------- test/Garnet.test/IndexGrowthTests.cs | 16 ++-- test/Garnet.test/NUnitLoggerProvider.cs | 6 +- test/Garnet.test/ReqGen.cs | 2 +- test/Garnet.test/RespAdminCommandsTests.cs | 4 +- test/Garnet.test/RespAofAzureTests.cs | 22 +++-- test/Garnet.test/RespAofTests.cs | 22 +++-- test/Garnet.test/RespCustomCommandTests.cs | 46 ++++++---- test/Garnet.test/RespHashTests.cs | 42 ++++----- test/Garnet.test/RespListTests.cs | 70 +++++++-------- test/Garnet.test/RespScanCommandsTests.cs | 84 +++++++++--------- test/Garnet.test/RespSetTest.cs | 70 +++++++-------- .../RespSortedSetGarnetClientTests.cs | 85 +++++++++---------- test/Garnet.test/RespSortedSetGeoTests.cs | 6 +- test/Garnet.test/RespSortedSetTests.cs | 78 ++++++++--------- test/Garnet.test/RespTests.cs | 22 ++--- test/Garnet.test/RespTransactionProcTests.cs | 4 +- test/Garnet.test/TestProcedureBitmap.cs | 8 +- test/Garnet.test/TestProcedureHLL.cs | 2 +- test/Garnet.test/TestUtils.cs | 2 +- 25 files changed, 383 insertions(+), 375 deletions(-) diff --git a/test/Garnet.test/CacheSizeTrackerTests.cs b/test/Garnet.test/CacheSizeTrackerTests.cs index 3fc9b1b7a..92a375613 100644 --- a/test/Garnet.test/CacheSizeTrackerTests.cs +++ b/test/Garnet.test/CacheSizeTrackerTests.cs @@ -41,7 +41,7 @@ public void HeapSizeValidationTest() using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Faster") }); + db.HashSet("user:user1", [new HashEntry("Title", "Faster")]); string r = db.HashGet("user:user1", "Title"); Assert.AreEqual("Faster", r); @@ -60,7 +60,7 @@ public void IncreaseEmptyPageCountTest() using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Faster") }); + db.HashSet("user:user1", [new HashEntry("Title", "Faster")]); string r = db.HashGet("user:user1", "Title"); Assert.AreEqual("Faster", r); @@ -70,7 +70,7 @@ public void IncreaseEmptyPageCountTest() // Have enough records (24 bytes each) to cross a page boundary (512) for (int i = 2; i <= 24; i++) { - db.HashSet($"user:user{i}", new HashEntry[] { new HashEntry("Title", "Faster") }); + db.HashSet($"user:user{i}", [new HashEntry("Title", "Faster")]); } Assert.AreEqual(5952, cacheSizeTracker.mainLogTracker.LogHeapSizeBytes); // 24 * 248 for each hashset object diff --git a/test/Garnet.test/GarnetBitmapTests.cs b/test/Garnet.test/GarnetBitmapTests.cs index 0252e0e7d..bfbd0b10a 100644 --- a/test/Garnet.test/GarnetBitmapTests.cs +++ b/test/Garnet.test/GarnetBitmapTests.cs @@ -175,7 +175,7 @@ public void BitmapSetGetBitTest_LTM(bool preSet) int keyCount = 8; int keyIter = 256; byte[] bitmap = new byte[bitmapBytes]; - Dictionary> state = new Dictionary>(); + Dictionary> state = []; if (preSet) { @@ -213,7 +213,7 @@ public void BitmapSetGetBitTest_LTM(bool preSet) } else { - state.Add(key, new Dictionary()); + state.Add(key, []); state[key].Add(offset, set); } @@ -312,7 +312,7 @@ public void BitmapBitCountBetweenOffsetsTest() int maxBitmapLen = 1 << 12; int iter = 1024; - List offsets = new List(); + List offsets = []; long maxOffset = 0; for (int i = 0; i < iter; i++) { @@ -456,7 +456,7 @@ public void BitmapBitCountTest_LTM() int keyCount = 64; byte[] bitmap = new byte[bitmapBytes]; - List bitmapList = new List(); + List bitmapList = []; for (int i = 0; i < keyCount; i++) { @@ -653,7 +653,7 @@ public void BitmapBitPosTest_LTM() int keyCount = 64; byte[] bitmap = new byte[bitmapBytes]; - List bitmapList = new List(); + List bitmapList = []; for (int i = 0; i < keyCount; i++) { @@ -738,8 +738,8 @@ public unsafe void BitmapSimpleBITOP_PCT(int bytesPerSend) //Test AND, OR, XOR long srcA, srcB, srcC; - RedisKey[] keys = new RedisKey[] { a, b, c }; - Bitwise[] bitwiseOps = new Bitwise[] { Bitwise.And, Bitwise.Or, Bitwise.Xor }; + RedisKey[] keys = [a, b, c]; + Bitwise[] bitwiseOps = [Bitwise.And, Bitwise.Or, Bitwise.Xor]; for (int j = 0; j < bitwiseOps.Length; j++) { for (int i = 0; i < tests; i++) @@ -820,8 +820,8 @@ public void BitmapSimpleBitOpTests() //Test AND, OR, XOR long srcA, srcB, srcC; - RedisKey[] keys = new RedisKey[] { a, b, c }; - Bitwise[] bitwiseOps = new Bitwise[] { Bitwise.And, Bitwise.Or, Bitwise.Xor }; + RedisKey[] keys = [a, b, c]; + Bitwise[] bitwiseOps = [Bitwise.And, Bitwise.Or, Bitwise.Xor]; for (int j = 0; j < bitwiseOps.Length; j++) { for (int i = 0; i < tests; i++) @@ -904,8 +904,8 @@ public void BitmapSimpleVarLenBitOpTests() string d = "d"; string x = "x"; - RedisKey[] keys = new RedisKey[] { a, b, c, d }; - Bitwise[] bitwiseOps = new Bitwise[] { Bitwise.And, Bitwise.Or, Bitwise.Xor, Bitwise.And, Bitwise.Or, Bitwise.Xor }; + RedisKey[] keys = [a, b, c, d]; + Bitwise[] bitwiseOps = [Bitwise.And, Bitwise.Or, Bitwise.Xor, Bitwise.And, Bitwise.Or, Bitwise.Xor]; int maxBytes = 512; byte[] dataA = new byte[r.Next(1, maxBytes)]; @@ -1016,8 +1016,8 @@ public void BitmapSimpleBitOpVarLenGrowingSizeTests() byte[] dataA, dataB, dataC, dataD; byte[] dataX; int minSize = 512; - Bitwise[] bitwiseOps = new Bitwise[] { Bitwise.And, Bitwise.Or, Bitwise.Xor, Bitwise.And, Bitwise.Or, Bitwise.Xor }; - RedisKey[] keys = new RedisKey[] { a, b, c, d }; + Bitwise[] bitwiseOps = [Bitwise.And, Bitwise.Or, Bitwise.Xor, Bitwise.And, Bitwise.Or, Bitwise.Xor]; + RedisKey[] keys = [a, b, c, d]; //Test NOT for (int i = 0; i < tests; i++) @@ -1094,7 +1094,7 @@ private long GetValueFromBitmap(ref byte[] bitmap, long offset, int bitCount, bo long indexBit = 0; long value = 0; int bI = 63; - byte[] si = { 1, 2, 4, 8, 16, 32, 64, 128 }; + byte[] si = [1, 2, 4, 8, 16, 32, 64, 128]; while (indexBit < (bitmap.Length << 3)) { for (int i = 7; i >= 0; i--) @@ -1148,19 +1148,11 @@ private long getSigned(ref byte[] bitmap, ulong offset, ulong bits) { ulong value = getUnsigned(ref bitmap, offset, bits); - ulong[] si = { - 1L << 0, 1L << 1, 1L << 2, 1L << 3, 1L << 4, 1L << 5, 1L << 6, 1L << 7,//0 - 1L << 8, 1L << 9, 1L << 10, 1L << 11, 1L << 12, 1L << 13, 1L << 14, 1L << 15,//1 - 1L << 16, 1L << 17, 1L << 18, 1L << 19, 1L << 20, 1L << 21, 1L << 22, 1L << 23,//2 - 1L << 24, 1L << 25, 1L << 26, 1L << 27, 1L << 28, 1L << 29, 1L << 30, 1L << 31,//3 - 1L << 32, 1L << 33, 1L << 34, 1L << 35, 1L << 36, 1L << 37, 1L << 38, 1L << 39,//4 - 1L << 40, 1L << 41, 1L << 42, 1L << 43, 1L << 44, 1L << 45, 1L << 46, 1L << 47,//5 - 1L << 48, 1L << 49, 1L << 50, 1L << 51, 1L << 52, 1L << 53, 1L << 54, 1L << 55,//6 - 1L << 56, 1L << 57, 1L << 58, 1L << 59, 1L << 60, 1L << 61, 1L << 62, (ulong)1 << 63,//7 - }; - - if (bits < 64 && ((value & si[bits - 1]) > 0)) - value |= (~(ulong)0) << ((byte)bits); + if (bits < 64 && (value & (1UL << (int)(bits - 1))) != 0) + { + value |= ulong.MaxValue << (byte)bits; + } + return (long)value; } @@ -2098,7 +2090,7 @@ public void BitmapBitfieldGrowingTest() for (int j = 1; j <= 64; j++) { db.KeyDelete(key); - List values = new List(); + List values = []; bitCount = j; for (int i = 0; i < tests; i++) { @@ -2174,7 +2166,7 @@ public void BitmapBitfieldGrowingTest() for (int j = 1; j <= 64; j++) { bitCount = j; - List values = new List(); + List values = []; db.KeyDelete(key); for (int i = 0; i < tests; i++) diff --git a/test/Garnet.test/GarnetClientTests.cs b/test/Garnet.test/GarnetClientTests.cs index d573b66b9..c723ba280 100644 --- a/test/Garnet.test/GarnetClientTests.cs +++ b/test/Garnet.test/GarnetClientTests.cs @@ -187,8 +187,8 @@ public async Task SimpleStringArrayTest([Values] bool stringParams) db.Connect(); long n = stringParams ? - int.Parse(await db.ExecuteForStringResultAsync("INCRBY", new string[] { "myKey", "10" })) : - int.Parse(await db.ExecuteForStringResultAsync(Encoding.ASCII.GetBytes("$6\r\nINCRBY\r\n"), new Memory[] { Encoding.ASCII.GetBytes("myKey"), Encoding.ASCII.GetBytes("10") })); + int.Parse(await db.ExecuteForStringResultAsync("INCRBY", ["myKey", "10"])) : + int.Parse(await db.ExecuteForStringResultAsync(Encoding.ASCII.GetBytes("$6\r\nINCRBY\r\n"), [Encoding.ASCII.GetBytes("myKey"), Encoding.ASCII.GetBytes("10")])); Assert.AreEqual(10, n); } @@ -342,10 +342,10 @@ public async Task CanUseSetNxStringResultAsync() var db = TestUtils.GetGarnetClient(); db.Connect(); - var result = await db.ExecuteForStringResultAsync("SET", new string[] { "mykey", "Hello", "NX" }); + var result = await db.ExecuteForStringResultAsync("SET", ["mykey", "Hello", "NX"]); Assert.AreEqual("OK", result); - result = await db.ExecuteForStringResultAsync("SET", new string[] { "mykey", "World", "NX" }); + result = await db.ExecuteForStringResultAsync("SET", ["mykey", "World", "NX"]); Assert.AreEqual(null, result); var resultMykey = await db.StringGetAsync("mykey"); @@ -366,7 +366,7 @@ public async Task CanUseMGetTests([Values] bool disableObjectStore) for (int i = 0; i < nKeys; i++) { - var result = await db.ExecuteForStringResultAsync("SET", new string[] { worldcities[i, 1], worldcities[i, 0] }); + var result = await db.ExecuteForStringResultAsync("SET", [worldcities[i, 1], worldcities[i, 0]]); keys[i] = worldcities[i, 1]; keysMemory[i] = Encoding.ASCII.GetBytes(keys[i]); Assert.AreEqual("OK", result); @@ -477,7 +477,7 @@ public async Task CanDoBulkDeleteTests([Values] bool useStringType) for (int i = 0; i < nKeys; i++) { // create in the main store - var result = await db.ExecuteForStringResultAsync("SET", new string[] { worldcities[i, 1], worldcities[i, 0] }); + var result = await db.ExecuteForStringResultAsync("SET", [worldcities[i, 1], worldcities[i, 0]]); keys[i] = worldcities[i, 1]; keysMemoryByte[i] = Encoding.ASCII.GetBytes(keys[i]); Assert.AreEqual("OK", result); @@ -486,10 +486,7 @@ public async Task CanDoBulkDeleteTests([Values] bool useStringType) for (int x = 0; x < nKeysObjectStore; x++) { // create in the object store - List parameters = new(); - parameters = new List(); - parameters.AddRange(new string[] { $"myzset{x}", "1", "KEY1", "2", "KEY2" }); - var result = await db.ExecuteForStringResultAsync("ZADD", parameters); + var result = await db.ExecuteForStringResultAsync("ZADD", [$"myzset{x}", "1", "KEY1", "2", "KEY2"]); Assert.AreEqual("2", result); keys[nKeys + x] = $"myzset{x}"; keysMemoryByte[nKeys + x] = Encoding.ASCII.GetBytes(keys[nKeys + x]); @@ -553,7 +550,7 @@ public async Task CanDoBulkDeleteTests([Values] bool useStringType) //check that none of the keys exist foreach (var key in keys) { - var result = await db.ExecuteForStringResultAsync("EXISTS", new string[] { key }); + var result = await db.ExecuteForStringResultAsync("EXISTS", [key]); Assert.AreEqual("0", result); } } diff --git a/test/Garnet.test/GarnetObjectTests.cs b/test/Garnet.test/GarnetObjectTests.cs index 919547930..316d1da50 100644 --- a/test/Garnet.test/GarnetObjectTests.cs +++ b/test/Garnet.test/GarnetObjectTests.cs @@ -55,7 +55,7 @@ public async Task WriteCheckpointRead() var key = new byte[] { 0 }; var obj = new SortedSetObject(); - obj.Add(new byte[] { 15 }, 10); + obj.Add([15], 10); session.Upsert(key, obj); @@ -86,7 +86,7 @@ public async Task CopyUpdate() var key = new byte[] { 0 }; IGarnetObject obj = new SortedSetObject(); - ((SortedSetObject)obj).Add(new byte[] { 15 }, 10); + ((SortedSetObject)obj).Add([15], 10); session.Upsert(key, obj); diff --git a/test/Garnet.test/GarnetServerConfigTests.cs b/test/Garnet.test/GarnetServerConfigTests.cs index 6909a02e6..8e813453d 100644 --- a/test/Garnet.test/GarnetServerConfigTests.cs +++ b/test/Garnet.test/GarnetServerConfigTests.cs @@ -41,7 +41,7 @@ public void DefaultConfigurationOptionsCoverage() } } // Deserialize default.conf to get all defined default options - Dictionary jsonSettings = new Dictionary(); + Dictionary jsonSettings = []; try { jsonSettings = JsonConvert.DeserializeObject>(json); @@ -95,7 +95,7 @@ public void ImportExportConfigLocal() // Import from previous export command, no command line args // Check values from import path override values from default.conf - args = new string[] { "--config-import-path", configPath }; + args = ["--config-import-path", configPath]; parseSuccessful = ServerSettingsManager.TryParseCommandLineArguments(args, out options, out invalidOptions); Assert.IsTrue(parseSuccessful); Assert.AreEqual(invalidOptions.Count, 0); @@ -104,7 +104,7 @@ public void ImportExportConfigLocal() // Import from previous export command, include command line args, export to file // Check values from import path override values from default.conf, and values from command line override values from default.conf and import path - args = new string[] { "--config-import-path", configPath, "-p", "12m", "-s", "1g", "--recover", "false", "--port", "0", "--no-obj", "--aof" }; + args = ["--config-import-path", configPath, "-p", "12m", "-s", "1g", "--recover", "false", "--port", "0", "--no-obj", "--aof"]; parseSuccessful = ServerSettingsManager.TryParseCommandLineArguments(args, out options, out invalidOptions); Assert.IsTrue(parseSuccessful); Assert.AreEqual(invalidOptions.Count, 0); @@ -118,7 +118,7 @@ public void ImportExportConfigLocal() // No import path, include command line args // Check that all invalid options flagged - args = new string[] { "--bind", "1.1.1.257", "-m", "12mg", "--port", "-1", "--mutable-percent", "101", "--acl-file", "nx_dir/nx_file.txt", "--tls", "--reviv-fraction", "1.1", "--cert-file-name", "testcert.crt" }; + args = ["--bind", "1.1.1.257", "-m", "12mg", "--port", "-1", "--mutable-percent", "101", "--acl-file", "nx_dir/nx_file.txt", "--tls", "--reviv-fraction", "1.1", "--cert-file-name", "testcert.crt"]; parseSuccessful = ServerSettingsManager.TryParseCommandLineArguments(args, out options, out invalidOptions); Assert.IsFalse(parseSuccessful); Assert.IsNull(options); @@ -167,7 +167,7 @@ public void ImportExportRedisConfigLocal() // Import from redis.conf file, include command line args // Check values from import path override values from default.conf, and values from command line override values from default.conf and import path - args = new[] { "--config-import-path", redisConfigPath, "--config-import-format", "RedisConf", "--config-export-path", garnetConfigPath, "-p", "12m", "--tls", "false", "--minthreads", "6", "--client-certificate-required", "true" }; + args = ["--config-import-path", redisConfigPath, "--config-import-format", "RedisConf", "--config-export-path", garnetConfigPath, "-p", "12m", "--tls", "false", "--minthreads", "6", "--client-certificate-required", "true"]; parseSuccessful = ServerSettingsManager.TryParseCommandLineArguments(args, out options, out invalidOptions); Assert.IsTrue(parseSuccessful); Assert.AreEqual(invalidOptions.Count, 0); @@ -210,7 +210,7 @@ public void ImportExportConfigAzure() Assert.IsTrue(options.PageSize == "4m"); Assert.IsTrue(options.MemorySize == "8g"); - args = new string[] { "--storage-string", AzureEmulatedStorageString, "--use-azure-storage-for-config-import", "true", "--config-import-path", configPath }; + args = ["--storage-string", AzureEmulatedStorageString, "--use-azure-storage-for-config-import", "true", "--config-import-path", configPath]; parseSuccessful = ServerSettingsManager.TryParseCommandLineArguments(args, out options, out invalidOptions); Assert.IsTrue(parseSuccessful); Assert.AreEqual(invalidOptions.Count, 0); diff --git a/test/Garnet.test/HyperLogLogTests.cs b/test/Garnet.test/HyperLogLogTests.cs index d72801c16..feb45c03d 100644 --- a/test/Garnet.test/HyperLogLogTests.cs +++ b/test/Garnet.test/HyperLogLogTests.cs @@ -38,7 +38,7 @@ public void SimpleHyperLogLogAddCount() using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - string[] data = new string[] { "a", "b", "c", "d", "e", "f" }; + string[] data = ["a", "b", "c", "d", "e", "f"]; string key = "hllKey"; bool fUpdated = false; @@ -66,8 +66,8 @@ public static void SimpleHyperLogLogArrayAddCount() using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - RedisValue[] x = new RedisValue[] { "h", "e", "l", "l", "o" }; - RedisValue[] y = new RedisValue[] { "w", "o", "r", "l", "d" }; + RedisValue[] x = ["h", "e", "l", "l", "o"]; + RedisValue[] y = ["w", "o", "r", "l", "d"]; string keyX = "x"; var ret = db.HyperLogLogAdd(keyX, x); @@ -87,8 +87,8 @@ public void SimpleHyperLogLogMerge() using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - RedisValue[] x = new RedisValue[] { "h", "e", "l", "l", "o" }; - RedisValue[] y = new RedisValue[] { "w", "o", "r", "l", "d" }; + RedisValue[] x = ["h", "e", "l", "l", "o"]; + RedisValue[] y = ["w", "o", "r", "l", "d"]; string keyX = "x"; string keyY = "y"; string keyW = "w"; @@ -117,8 +117,8 @@ public void HyperLogLogSimpleInvalidHLLTypeTest() using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - RedisValue[] x = new RedisValue[] { "h", "e", "l", "l", "o" }; - RedisValue[] y = new RedisValue[] { "w", "o", "r", "l", "d" }; + RedisValue[] x = ["h", "e", "l", "l", "o"]; + RedisValue[] y = ["w", "o", "r", "l", "d"]; string keyX = "x"; string keyY = "y"; string keyW = "w"; @@ -451,13 +451,13 @@ public void HyperLogLogMultiCountTest() using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - RedisValue[] dataA = new RedisValue[] { "h", "e", "l", "l", "o" }; - RedisValue[] dataB = new RedisValue[] { "w", "o", "r", "l", "d" }; - RedisValue[] dataC = new RedisValue[] { "a", "b", "c", "d", "e", "f" }; + RedisValue[] dataA = ["h", "e", "l", "l", "o"]; + RedisValue[] dataB = ["w", "o", "r", "l", "d"]; + RedisValue[] dataC = ["a", "b", "c", "d", "e", "f"]; string keyA = "HyperLogLogMultiCountTestA"; string keyB = "HyperLogLogMultiCountTestB"; string keyC = "HyperLogLogMultiCountTestC"; - RedisKey[] keys = new RedisKey[] { keyA, keyB, keyC }; + RedisKey[] keys = [keyA, keyB, keyC]; db.KeyDelete(keyA); db.KeyDelete(keyB); @@ -491,14 +491,14 @@ public void HyperLogLogMultiCountTest() public List RandomSubSeq(List list, int count) { - List rss = new List(); + List rss = []; for (int i = 0; i < count; i++) rss.Add(list[r.Next(list.Count)]); return rss; } public RedisValue[] RandomRedisValueSubseq(List list, int count) { - List rss = new List(); + List rss = []; for (int i = 0; i < count; i++) rss.Add(list[r.Next(list.Count)]); return rss.ToArray(); @@ -521,8 +521,8 @@ public void HyperLogLogTestPFADDV2() var keyA = System.Text.Encoding.ASCII.GetBytes("HyperLogLogTestPFADDA");//sparse var keyB = System.Text.Encoding.ASCII.GetBytes("HyperLogLogTestPFADDB");//sparse - HashSet setA = new HashSet(); - HashSet setB = new HashSet(); + HashSet setA = []; + HashSet setB = []; for (int i = 0; i < smallSeq; i++) { @@ -584,7 +584,7 @@ public void HyperLogLogPFADD_LTM(int seqSize) int keyCount = sparse ? 32 : 4; int smallSeq = seqSize; - Dictionary> hllKeyCollection = new Dictionary>(); + Dictionary> hllKeyCollection = []; //1. Populate HLL for (int i = 0; i < keyCount; i++) @@ -592,7 +592,7 @@ public void HyperLogLogPFADD_LTM(int seqSize) int key = i; string sKey = key.ToString(); - hllKeyCollection.Add(key, new HashSet()); + hllKeyCollection.Add(key, []); for (int j = 0; j < smallSeq; j++) { long valA = LongRandom(); @@ -622,8 +622,8 @@ public void HyperLogLogTestPFADD_DuplicatesV2() int smallSeq = 1 << 10; int largeSeq = 1 << 15; var keyA = System.Text.Encoding.ASCII.GetBytes("keyA");//sparse - HashSet setA = new HashSet(); - List largeInput = new List(); + HashSet setA = []; + List largeInput = []; for (int i = 0; i < largeSeq; i++) largeInput.Add(LongRandom()); @@ -651,11 +651,11 @@ public void HyperLogLogTestPFMERGE_SparseToSparseV2() var keyA = System.Text.Encoding.ASCII.GetBytes("SSkeyA");//sparse var keyB = System.Text.Encoding.ASCII.GetBytes("SSkeyB");//sparse - HashSet setA = new HashSet(); - HashSet setB = new HashSet(); + HashSet setA = []; + HashSet setB = []; long estimate = 0; - List largeInput = new List(); + List largeInput = []; RedisValue[] rss; for (int i = 0; i < largeSeq; i++) largeInput.Add(LongRandom()); @@ -697,7 +697,7 @@ public void HyperLogLogTestPFMERGE_LTM_SparseToSparse() int keyCount = 64; int smallSeq = 32; - Dictionary> hllKeyCollection = new Dictionary>(); + Dictionary> hllKeyCollection = []; //1. Populate HLL for (int i = 0; i < keyCount; i++) @@ -705,7 +705,7 @@ public void HyperLogLogTestPFMERGE_LTM_SparseToSparse() int key = i; string sKey = key.ToString(); - hllKeyCollection.Add(key, new HashSet()); + hllKeyCollection.Add(key, []); for (int j = 0; j < smallSeq; j++) { long valA = LongRandom(); @@ -752,12 +752,12 @@ public void HyperLogLogTestPFMERGE_SparseToDenseV2() var keyA = System.Text.Encoding.ASCII.GetBytes("SDkeyA");//sparse var keyB = System.Text.Encoding.ASCII.GetBytes("SDkeyB");//dense var keyC = System.Text.Encoding.ASCII.GetBytes("SDkeyC");//dense - HashSet setA = new HashSet(); - HashSet setB = new HashSet(); - HashSet setC = new HashSet(); + HashSet setA = []; + HashSet setB = []; + HashSet setC = []; long estimate = 0; - List largeInput = new List(); + List largeInput = []; RedisValue[] rss; for (int i = 0; i < largeSeq; i++) largeInput.Add(LongRandom()); @@ -807,7 +807,7 @@ public void HyperLogLogTestPFMERGE_LTM_SparseToDense(bool reverse) int smallSeq = 32; int largeSeq = 1 << 13; - Dictionary> hllKeyCollection = new Dictionary>(); + Dictionary> hllKeyCollection = []; //1. Populate HLL for (int i = 0; i < keyCount; i++) @@ -815,7 +815,7 @@ public void HyperLogLogTestPFMERGE_LTM_SparseToDense(bool reverse) int key = i; string sKey = key.ToString(); - hllKeyCollection.Add(key, new HashSet()); + hllKeyCollection.Add(key, []); int seq = i % 2 == 0 ? smallSeq : largeSeq; for (int j = 0; j < seq; j++) { @@ -863,12 +863,12 @@ public void HyperLogLogTestPFMERGE_DenseToDenseV2() var keyA = System.Text.Encoding.ASCII.GetBytes("DDkeyA");//dense var keyB = System.Text.Encoding.ASCII.GetBytes("DDkeyB");//dense var keyC = System.Text.Encoding.ASCII.GetBytes("DDkeyC");//dense - HashSet setA = new HashSet(); - HashSet setB = new HashSet(); - HashSet setC = new HashSet(); + HashSet setA = []; + HashSet setB = []; + HashSet setC = []; long estimate = 0; - List largeInput = new List(); + List largeInput = []; RedisValue[] rss; for (int i = 0; i < largeSeq; i++) largeInput.Add(LongRandom()); @@ -916,7 +916,7 @@ public void HyperLogLogTestPFMERGE_LTM_DenseToDense() int keyCount = 4; int largeSeq = 1 << 13; - Dictionary> hllKeyCollection = new Dictionary>(); + Dictionary> hllKeyCollection = []; //1. Populate HLL for (int i = 0; i < keyCount; i++) @@ -924,7 +924,7 @@ public void HyperLogLogTestPFMERGE_LTM_DenseToDense() int key = i; string sKey = key.ToString(); - hllKeyCollection.Add(key, new HashSet()); + hllKeyCollection.Add(key, []); for (int j = 0; j < largeSeq; j++) { long valA = LongRandom(); @@ -967,11 +967,11 @@ public void HyperLogLogPFMerge_MultiHLLMergeV2() int smallSeq = 1 << 10; int largeSeq = 1 << 14; int hllCount = 10; - HashSet dstSet = new HashSet(); + HashSet dstSet = []; int srcKey = r.Next(1024, 2048); RedisKey[] srcKeys = new RedisKey[hllCount]; - List values = new List(); + List values = []; for (int i = 0; i < largeSeq; i++) values.Add(LongRandom()); diff --git a/test/Garnet.test/IndexGrowthTests.cs b/test/Garnet.test/IndexGrowthTests.cs index 26aa92e2c..3b657a182 100644 --- a/test/Garnet.test/IndexGrowthTests.cs +++ b/test/Garnet.test/IndexGrowthTests.cs @@ -36,8 +36,8 @@ public void IndexGrowthTest() var store = server.Provider.StoreWrapper.store; - RedisKey[] keys = { "abcdkey", "bcdekey", "cdefkey", "defgkey", "efghkey", "fghikey", "ghijkey", "hijkkey" }; - RedisValue[] values = { "abcdval", "bcdeval", "cdefval", "defgval", "efghval", "fghival", "ghijval", "hijkval" }; + RedisKey[] keys = ["abcdkey", "bcdekey", "cdefkey", "defgkey", "efghkey", "fghikey", "ghijkey", "hijkkey"]; + RedisValue[] values = ["abcdval", "bcdeval", "cdefval", "defgval", "efghval", "fghival", "ghijval", "hijkval"]; using (var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(allowAdmin: true))) { @@ -74,8 +74,8 @@ public void ObjectStoreIndexGrowthTest() var objectStore = server.Provider.StoreWrapper.objectStore; - RedisKey[] keys = { "abcdkey", "bcdekey", "cdefkey", "defgkey", "efghkey", "fghikey", "ghijkey", "hijkkey" }; - RedisValue[] values = { "abcdval", "bcdeval", "cdefval", "defgval", "efghval", "fghival", "ghijval", "hijkval" }; + RedisKey[] keys = ["abcdkey", "bcdekey", "cdefkey", "defgkey", "efghkey", "fghikey", "ghijkey", "hijkkey"]; + RedisValue[] values = ["abcdval", "bcdeval", "cdefval", "defgval", "efghval", "fghival", "ghijval", "hijkval"]; using (var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(allowAdmin: true))) { @@ -121,8 +121,8 @@ public void IndexGrowthTestWithDiskReadAndCheckpoint() var store = server.Provider.StoreWrapper.store; - RedisKey[] keys = { "abcdkey", "bcdekey", "cdefkey", "defgkey", "efghkey", "fghikey", "ghijkey", "hijkkey" }; - RedisValue[] values = { "abcdval", "bcdeval", "cdefval", "defgval", "efghval", "fghival", "ghijval", "hijkval" }; + RedisKey[] keys = ["abcdkey", "bcdekey", "cdefkey", "defgkey", "efghkey", "fghikey", "ghijkey", "hijkkey"]; + RedisValue[] values = ["abcdval", "bcdeval", "cdefval", "defgval", "efghval", "fghival", "ghijval", "hijkval"]; Random rnd = new Random(42); using (var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(allowAdmin: true))) @@ -185,8 +185,8 @@ public void ObjectStoreIndexGrowthTestWithDiskReadAndCheckpoint() var objectStore = server.Provider.StoreWrapper.objectStore; - RedisKey[] keys = { "abcdkey", "bcdekey", "cdefkey", "defgkey", "efghkey", "fghikey", "ghijkey", "hijkkey" }; - RedisValue[] values = { "abcdval", "bcdeval", "cdefval", "defgval", "efghval", "fghival", "ghijval", "hijkval" }; + RedisKey[] keys = ["abcdkey", "bcdekey", "cdefkey", "defgkey", "efghkey", "fghikey", "ghijkey", "hijkkey"]; + RedisValue[] values = ["abcdval", "bcdeval", "cdefval", "defgval", "efghval", "fghival", "ghijval", "hijkval"]; Random rnd = new Random(42); using (var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig(allowAdmin: true))) diff --git a/test/Garnet.test/NUnitLoggerProvider.cs b/test/Garnet.test/NUnitLoggerProvider.cs index 9889e6ae2..571c36520 100644 --- a/test/Garnet.test/NUnitLoggerProvider.cs +++ b/test/Garnet.test/NUnitLoggerProvider.cs @@ -18,15 +18,15 @@ public class NUnitLoggerProvider : ILoggerProvider private readonly bool matchLevel; private readonly LogLevel logLevel; - static readonly string[] lvl = new string[] - { + static readonly string[] lvl = + [ "trce", "dbug", "info", "warn", "errr", "crit", - }; + ]; public NUnitLoggerProvider(TextWriter textWriter, string scope = "", HashSet skipCmd = null, bool recvOnly = false, bool matchLevel = false, LogLevel logLevel = LogLevel.None) { diff --git a/test/Garnet.test/ReqGen.cs b/test/Garnet.test/ReqGen.cs index b874e3d24..8d5b6a0cd 100644 --- a/test/Garnet.test/ReqGen.cs +++ b/test/Garnet.test/ReqGen.cs @@ -50,7 +50,7 @@ public ReqGen(OpType opType, int srcKeys = 1) { int len = 0; int index = offset; - List values = new(); + List values = []; fixed (byte* buf = buffer, opBuf = opHeader) { diff --git a/test/Garnet.test/RespAdminCommandsTests.cs b/test/Garnet.test/RespAdminCommandsTests.cs index 93725a97c..72a1256b2 100644 --- a/test/Garnet.test/RespAdminCommandsTests.cs +++ b/test/Garnet.test/RespAdminCommandsTests.cs @@ -351,9 +351,9 @@ public async Task SeFlushDBTest([Values] bool async, [Values] bool unsafetruncat string[] p = default; if (async && unsafetruncatelog) - p = new string[] { "ASYNC", "UNSAFETRUNCATELOG" }; + p = ["ASYNC", "UNSAFETRUNCATELOG"]; else if (unsafetruncatelog) - p = new string[] { "UNSAFETRUNCATELOG" }; + p = ["UNSAFETRUNCATELOG"]; if (async) { diff --git a/test/Garnet.test/RespAofAzureTests.cs b/test/Garnet.test/RespAofAzureTests.cs index 0281e84c3..8bd13bf66 100644 --- a/test/Garnet.test/RespAofAzureTests.cs +++ b/test/Garnet.test/RespAofAzureTests.cs @@ -12,13 +12,19 @@ namespace Garnet.test public class RespAofAzureTests { GarnetServer server; - static readonly SortedSetEntry[] entries = new SortedSetEntry[] - { - new SortedSetEntry("a", 1), new SortedSetEntry("b", 2), new SortedSetEntry("c", 3), - new SortedSetEntry("d", 4), new SortedSetEntry("e", 5), new SortedSetEntry("f", 6), - new SortedSetEntry("g", 7), new SortedSetEntry("h", 8), new SortedSetEntry("i", 9), + static readonly SortedSetEntry[] entries = + [ + new SortedSetEntry("a", 1), + new SortedSetEntry("b", 2), + new SortedSetEntry("c", 3), + new SortedSetEntry("d", 4), + new SortedSetEntry("e", 5), + new SortedSetEntry("f", 6), + new SortedSetEntry("g", 7), + new SortedSetEntry("h", 8), + new SortedSetEntry("i", 9), new SortedSetEntry("j", 10) - }; + ]; [SetUp] public void Setup() @@ -330,7 +336,7 @@ public void AofRMWObjectStoreCopyUpdateRecoverTest() var db = redis.GetDatabase(0); for (int i = 0; i < 100; i++) { - SortedSetEntry[] entry = new SortedSetEntry[] { new SortedSetEntry("a", 1), new SortedSetEntry("b", 2) }; + SortedSetEntry[] entry = [new SortedSetEntry("a", 1), new SortedSetEntry("b", 2)]; db.SortedSetAdd(key + i, entry); var score = db.SortedSetScore(key + i, "a"); @@ -338,7 +344,7 @@ public void AofRMWObjectStoreCopyUpdateRecoverTest() Assert.AreEqual(1, score.Value); } - SortedSetEntry[] newEntries = new SortedSetEntry[] { new SortedSetEntry("bbbb", 4) }; + SortedSetEntry[] newEntries = [new SortedSetEntry("bbbb", 4)]; db.SortedSetAdd("AofRMWObjectStoreRecoverTestKey" + 1, newEntries); } server.Store.CommitAOF(true); diff --git a/test/Garnet.test/RespAofTests.cs b/test/Garnet.test/RespAofTests.cs index f02a511a2..a52bd1d08 100644 --- a/test/Garnet.test/RespAofTests.cs +++ b/test/Garnet.test/RespAofTests.cs @@ -14,13 +14,19 @@ namespace Garnet.test public class RespAofTests { GarnetServer server; - static readonly SortedSetEntry[] entries = new SortedSetEntry[] - { - new SortedSetEntry("a", 1), new SortedSetEntry("b", 2), new SortedSetEntry("c", 3), - new SortedSetEntry("d", 4), new SortedSetEntry("e", 5), new SortedSetEntry("f", 6), - new SortedSetEntry("g", 7), new SortedSetEntry("h", 8), new SortedSetEntry("i", 9), + static readonly SortedSetEntry[] entries = + [ + new SortedSetEntry("a", 1), + new SortedSetEntry("b", 2), + new SortedSetEntry("c", 3), + new SortedSetEntry("d", 4), + new SortedSetEntry("e", 5), + new SortedSetEntry("f", 6), + new SortedSetEntry("g", 7), + new SortedSetEntry("h", 8), + new SortedSetEntry("i", 9), new SortedSetEntry("j", 10) - }; + ]; [SetUp] public void Setup() @@ -334,7 +340,7 @@ public void AofRMWObjectStoreCopyUpdateRecoverTest() var db = redis.GetDatabase(0); for (int i = 0; i < 100; i++) { - SortedSetEntry[] entry = new SortedSetEntry[] { new SortedSetEntry("a", 1), new SortedSetEntry("b", 2) }; + SortedSetEntry[] entry = [new SortedSetEntry("a", 1), new SortedSetEntry("b", 2)]; db.SortedSetAdd(key + i, entry); var score = db.SortedSetScore(key + i, "a"); @@ -342,7 +348,7 @@ public void AofRMWObjectStoreCopyUpdateRecoverTest() Assert.AreEqual(1, score.Value); } - SortedSetEntry[] newEntries = new SortedSetEntry[] { new SortedSetEntry("bbbb", 4) }; + SortedSetEntry[] newEntries = [new SortedSetEntry("bbbb", 4)]; db.SortedSetAdd("AofRMWObjectStoreRecoverTestKey" + 1, newEntries); } server.Store.CommitAOF(true); diff --git a/test/Garnet.test/RespCustomCommandTests.cs b/test/Garnet.test/RespCustomCommandTests.cs index 8d4c4ac37..50ef9506a 100644 --- a/test/Garnet.test/RespCustomCommandTests.cs +++ b/test/Garnet.test/RespCustomCommandTests.cs @@ -35,7 +35,7 @@ public void Setup() TestUtils.DeleteDirectory(TestUtils.MethodTestDir, wait: true); server = TestUtils.CreateGarnetServer(TestUtils.MethodTestDir, disablePubSub: true, - extensionBinPaths: new[] { _extTestDir1, _extTestDir2 }, + extensionBinPaths: [_extTestDir1, _extTestDir2], extensionAllowUnsignedAssemblies: true); server.Start(); } @@ -625,7 +625,7 @@ private string[] CreateTestLibraries() File.Copy(Path.Combine(dir1, "testLib1.dll"), notAllowedPath); } - return new[] { Path.Combine(dir1, "testLib1.dll"), dir2 }; + return [Path.Combine(dir1, "testLib1.dll"), dir2]; } [Test] @@ -726,7 +726,7 @@ public void RegisterCustomCommandErrorConditionsTest() // Malformed request #2 - binary paths before sub-command var args = new List() { "SRC" }; args.AddRange(libraryPaths); - args.AddRange(new object[] { "TXN", "READWRITETX", 3, "ReadWriteTxn" }); + args.AddRange(["TXN", "READWRITETX", 3, "ReadWriteTxn"]); try { @@ -739,11 +739,15 @@ public void RegisterCustomCommandErrorConditionsTest() Assert.IsNull(resp); // Binary file not contained in allowed paths - args = new List - { - "RMW", "MYDICTSET", 2, "MyDictFactory", - "SRC", Path.Combine(TestUtils.MethodTestDir, "testLib1.dll") - }; + args = + [ + "RMW", + "MYDICTSET", + 2, + "MyDictFactory", + "SRC", + Path.Combine(TestUtils.MethodTestDir, "testLib1.dll") + ]; try { @@ -756,12 +760,15 @@ public void RegisterCustomCommandErrorConditionsTest() Assert.IsNull(resp); // Class not in supplied dlls - args = new List - { - "RMW", "MYDICTSET", 2, "MyDictFactory", + args = + [ + "RMW", + "MYDICTSET", + 2, + "MyDictFactory", "SRC", - }; - args.AddRange(libraryPaths.Skip(1)); + .. libraryPaths.Skip(1), + ]; try { @@ -774,12 +781,15 @@ public void RegisterCustomCommandErrorConditionsTest() Assert.IsNull(resp); // Class not in supported - args = new List - { - "RMW", "MYDICTSET", 2, "TestClass", + args = + [ + "RMW", + "MYDICTSET", + 2, + "TestClass", "SRC", - }; - args.AddRange(libraryPaths); + .. libraryPaths, + ]; try { diff --git a/test/Garnet.test/RespHashTests.cs b/test/Garnet.test/RespHashTests.cs index a1f94d2ad..52d93364c 100644 --- a/test/Garnet.test/RespHashTests.cs +++ b/test/Garnet.test/RespHashTests.cs @@ -41,7 +41,7 @@ public void CanSetAndGetOnePair() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Tsavorite") }); + db.HashSet("user:user1", [new HashEntry("Title", "Tsavorite")]); string r = db.HashGet("user:user1", "Title"); Assert.AreEqual("Tsavorite", r); } @@ -52,7 +52,7 @@ public void CanSetAndGetOnePairLarge() using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); var str = new string(new char[150000]); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", str) }); + db.HashSet("user:user1", [new HashEntry("Title", str)]); string r = db.HashGet("user:user1", "Title"); Assert.AreEqual(str, r); string r2 = db.HashGet("user:user1", "Title2"); @@ -84,8 +84,8 @@ public void CanSetAndGetMultiplePairs() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021") }); - var result = db.HashGet("user:user1", new RedisValue[] { new RedisValue("Title"), new RedisValue("Year") }); + db.HashSet("user:user1", [new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021")]); + var result = db.HashGet("user:user1", [new RedisValue("Title"), new RedisValue("Year")]); Assert.AreEqual(2, result.Length); Assert.AreEqual("Tsavorite", result[0].ToString()); Assert.AreEqual("2021", result[1].ToString()); @@ -98,7 +98,7 @@ public void CanDelSingleField() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021") }); + db.HashSet("user:user1", [new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021")]); var result = db.HashDelete(new RedisKey("user:user1"), new RedisValue("Title")); Assert.AreEqual(true, result); string resultGet = db.HashGet("user:user1", "Year"); @@ -111,8 +111,8 @@ public void CanDeleleteMultipleFields() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Example", "One") }); - var result = db.HashDelete(new RedisKey("user:user1"), new RedisValue[] { new RedisValue("Title"), new RedisValue("Year") }); + db.HashSet("user:user1", [new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Example", "One")]); + var result = db.HashDelete(new RedisKey("user:user1"), [new RedisValue("Title"), new RedisValue("Year")]); string resultGet = db.HashGet("user:user1", "Example"); Assert.AreEqual("One", resultGet); } @@ -122,8 +122,8 @@ public void CanDeleleteMultipleFieldsWithNonExistingField() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021") }); - var result = db.HashDelete(new RedisKey("user:user1"), new RedisValue[] { new RedisValue("Title"), new RedisValue("Year"), new RedisValue("Unknown") }); + db.HashSet("user:user1", [new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021")]); + var result = db.HashDelete(new RedisKey("user:user1"), [new RedisValue("Title"), new RedisValue("Year"), new RedisValue("Unknown")]); Assert.AreEqual(2, result); } @@ -132,7 +132,7 @@ public void CanDoHLen() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Company", "Acme") }); + db.HashSet("user:user1", [new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Company", "Acme")]); var result = db.HashLength("user:user1"); Assert.AreEqual(3, result); } @@ -142,7 +142,7 @@ public void CanDoGetAll() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Company", "Acme") }); + db.HashSet("user:user1", [new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Company", "Acme")]); HashEntry[] result = db.HashGetAll("user:user1"); Assert.AreEqual(3, result.Length); } @@ -153,7 +153,7 @@ public void CanDoHExists() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Company", "Acme") }); + db.HashSet("user:user1", [new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Company", "Acme")]); var result = db.HashExists(new RedisKey("user:user1"), new RedisValue("Company")); Assert.AreEqual(true, result); @@ -166,7 +166,7 @@ public void CanDoHStrLen() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user.user1", new HashEntry[] { new HashEntry("Title", "Tsavorite") }); + db.HashSet("user.user1", [new HashEntry("Title", "Tsavorite")]); long r = db.HashStringLength("user.user1", "Title"); Assert.AreEqual(9, r, 0); r = db.HashStringLength("user.user1", "NoExist"); @@ -180,7 +180,7 @@ public void CanDoHKeys() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Company", "Acme") }); + db.HashSet("user:user1", [new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Company", "Acme")]); var result = db.HashKeys("user:user1"); Assert.AreEqual(3, result.Length); @@ -195,7 +195,7 @@ public void CanDoHVals() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Company", "Acme") }); + db.HashSet("user:user1", [new HashEntry("Title", "Tsavorite"), new HashEntry("Year", "2021"), new HashEntry("Company", "Acme")]); var result = db.HashValues("user:user1"); Assert.AreEqual(3, result.Length); @@ -210,7 +210,7 @@ public void CanDoHIncrBy() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Field1", "StringValue"), new HashEntry("Field2", "1") }); + db.HashSet("user:user1", [new HashEntry("Field1", "StringValue"), new HashEntry("Field2", "1")]); Assert.Throws(() => db.HashIncrement(new RedisKey("user:user1"), new RedisValue("Field1"), 4)); var result = db.HashIncrement(new RedisKey("user:user1"), new RedisValue("Field2"), -4); Assert.AreEqual(-3, result); @@ -230,7 +230,7 @@ public void CanDoHIncrByLTM() // Create LTM (larger than memory) DB by inserting 100 keys for (int i = 0; i < 100; i++) - db.HashSet("user:user" + i, new HashEntry[] { new HashEntry("Field1", "StringValue"), new HashEntry("Field2", "1") }); + db.HashSet("user:user" + i, [new HashEntry("Field1", "StringValue"), new HashEntry("Field2", "1")]); Assert.Throws(() => db.HashIncrement(new RedisKey("user:user1"), new RedisValue("Field1"), 4)); var result = db.HashIncrement(new RedisKey("user:user1"), new RedisValue("Field2"), -4); @@ -249,7 +249,7 @@ public void CanDoHashDecrement() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("Field1", "StringValue"), new HashEntry("Field2", "1") }); + db.HashSet("user:user1", [new HashEntry("Field1", "StringValue"), new HashEntry("Field2", "1")]); var result = db.HashDecrement(new RedisKey("user:user1"), new RedisValue("Field2"), 4); Assert.AreEqual(-3, result); } @@ -296,14 +296,14 @@ public void CanDoHashScan() Assert.IsTrue(((IScanningCursor)members).Cursor == 0); Assert.IsEmpty(members, "HSCAN non existing key failed."); - db.HashSet("user:user1", new HashEntry[] { new HashEntry("name", "Alice"), new HashEntry("email", "email@example.com"), new HashEntry("age", "30") }); + db.HashSet("user:user1", [new HashEntry("name", "Alice"), new HashEntry("email", "email@example.com"), new HashEntry("age", "30")]); // HSCAN without parameters members = db.HashScan("user:user1"); Assert.IsTrue(((IScanningCursor)members).Cursor == 0); Assert.IsTrue(members.Count() == 3, "HSCAN without MATCH failed."); - db.HashSet("user:user789", new HashEntry[] { new HashEntry("email", "email@example.com"), new HashEntry("email1", "email1@example.com"), new HashEntry("email2", "email2@example.com"), new HashEntry("email3", "email3@example.com"), new HashEntry("age", "25") }); + db.HashSet("user:user789", [new HashEntry("email", "email@example.com"), new HashEntry("email1", "email1@example.com"), new HashEntry("email2", "email2@example.com"), new HashEntry("email3", "email3@example.com"), new HashEntry("age", "25")]); // HSCAN with match members = db.HashScan("user:user789", "email*"); @@ -373,7 +373,7 @@ public async Task CanDoHMGET() db.KeyDelete(hashkey, CommandFlags.FireAndForget); - RedisValue[] fields = { "foo", "bar", "blop" }; + RedisValue[] fields = ["foo", "bar", "blop"]; var arr0 = await db.HashGetAsync(hashkey, fields); db.HashSet(hashkey, "foo", "abc", flags: CommandFlags.FireAndForget); diff --git a/test/Garnet.test/RespListTests.cs b/test/Garnet.test/RespListTests.cs index 866966325..74356220f 100644 --- a/test/Garnet.test/RespListTests.cs +++ b/test/Garnet.test/RespListTests.cs @@ -602,32 +602,32 @@ public async Task CanDoRPopLPushGC() db.Connect(); //If source does not exist, the value nil is returned and no operation is performed. - var response = await db.ExecuteForStringResultAsync("RPOPLPUSH", new string[] { "mylist", "myotherlist" }); + var response = await db.ExecuteForStringResultAsync("RPOPLPUSH", ["mylist", "myotherlist"]); Assert.AreEqual(null, response); - await db.ExecuteForStringResultAsync("RPUSH", new string[] { "mylist", "one" }); - await db.ExecuteForStringResultAsync("RPUSH", new string[] { "mylist", "two" }); - await db.ExecuteForStringResultAsync("RPUSH", new string[] { "mylist", "three" }); + await db.ExecuteForStringResultAsync("RPUSH", ["mylist", "one"]); + await db.ExecuteForStringResultAsync("RPUSH", ["mylist", "two"]); + await db.ExecuteForStringResultAsync("RPUSH", ["mylist", "three"]); - response = await db.ExecuteForStringResultAsync("RPOPLPUSH", new string[] { "mylist", "myotherlist" }); + response = await db.ExecuteForStringResultAsync("RPOPLPUSH", ["mylist", "myotherlist"]); Assert.AreEqual("three", response); - var responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", new string[] { "mylist", "0", "-1" }); + var responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", ["mylist", "0", "-1"]); var expectedResponseArray = new string[] { "one", "two" }; Assert.AreEqual(expectedResponseArray, responseArray); - responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", new string[] { "myotherlist", "0", "-1" }); - expectedResponseArray = new string[] { "three" }; + responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", ["myotherlist", "0", "-1"]); + expectedResponseArray = ["three"]; Assert.AreEqual(expectedResponseArray, responseArray); // if source and destination are the same //the operation is equivalent to removing the last element from the list and pushing it as first element of the list, //so it can be considered as a list rotation command. - response = await db.ExecuteForStringResultAsync("RPOPLPUSH", new string[] { "mylist", "mylist" }); + response = await db.ExecuteForStringResultAsync("RPOPLPUSH", ["mylist", "mylist"]); Assert.AreEqual("two", response); - responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", new string[] { "mylist", "0", "-1" }); - expectedResponseArray = new string[] { "two", "one" }; + responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", ["mylist", "0", "-1"]); + expectedResponseArray = ["two", "one"]; Assert.AreEqual(expectedResponseArray, responseArray); } @@ -646,45 +646,45 @@ public async Task CanUseLMoveGC() Assert.AreEqual("ERR syntax error", exception.Message); //If source does not exist, the value nil is returned and no operation is performed. - var response = await db.ExecuteForStringResultAsync("LMOVE", new string[] { "mylist", "myotherlist", "RIGHT", "LEFT" }); + var response = await db.ExecuteForStringResultAsync("LMOVE", ["mylist", "myotherlist", "RIGHT", "LEFT"]); Assert.AreEqual(null, response); - await db.ExecuteForStringResultAsync("RPUSH", new string[] { "mylist", "one" }); - await db.ExecuteForStringResultAsync("RPUSH", new string[] { "mylist", "two" }); - await db.ExecuteForStringResultAsync("RPUSH", new string[] { "mylist", "three" }); + await db.ExecuteForStringResultAsync("RPUSH", ["mylist", "one"]); + await db.ExecuteForStringResultAsync("RPUSH", ["mylist", "two"]); + await db.ExecuteForStringResultAsync("RPUSH", ["mylist", "three"]); - response = await db.ExecuteForStringResultAsync("LMOVE", new string[] { "mylist", "myotherlist", "RIGHT", "LEFT" }); + response = await db.ExecuteForStringResultAsync("LMOVE", ["mylist", "myotherlist", "RIGHT", "LEFT"]); Assert.AreEqual("three", response); - var responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", new string[] { "mylist", "0", "-1" }); + var responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", ["mylist", "0", "-1"]); var expectedResponseArray = new string[] { "one", "two" }; Assert.AreEqual(expectedResponseArray, responseArray); - responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", new string[] { "myotherlist", "0", "-1" }); - expectedResponseArray = new string[] { "three" }; + responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", ["myotherlist", "0", "-1"]); + expectedResponseArray = ["three"]; Assert.AreEqual(expectedResponseArray, responseArray); - response = await db.ExecuteForStringResultAsync("LMOVE", new string[] { "mylist", "myotherlist", "LEFT", "RIGHT" }); + response = await db.ExecuteForStringResultAsync("LMOVE", ["mylist", "myotherlist", "LEFT", "RIGHT"]); Assert.AreEqual("one", response); - responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", new string[] { "mylist", "0", "-1" }); - expectedResponseArray = new string[] { "two" }; + responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", ["mylist", "0", "-1"]); + expectedResponseArray = ["two"]; Assert.AreEqual(expectedResponseArray, responseArray); - responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", new string[] { "myotherlist", "0", "-1" }); - expectedResponseArray = new string[] { "three", "one" }; + responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", ["myotherlist", "0", "-1"]); + expectedResponseArray = ["three", "one"]; Assert.AreEqual(expectedResponseArray, responseArray); // if source and destination are the same //the operation is equivalent to a list rotation command. - response = await db.ExecuteForStringResultAsync("LMOVE", new string[] { "mylist", "mylist", "LEFT", "RIGHT" }); + response = await db.ExecuteForStringResultAsync("LMOVE", ["mylist", "mylist", "LEFT", "RIGHT"]); Assert.AreEqual("two", response); - response = await db.ExecuteForStringResultAsync("LMOVE", new string[] { "myotherlist", "myotherlist", "LEFT", "RIGHT" }); + response = await db.ExecuteForStringResultAsync("LMOVE", ["myotherlist", "myotherlist", "LEFT", "RIGHT"]); Assert.AreEqual("three", response); - responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", new string[] { "myotherlist", "0", "-1" }); - expectedResponseArray = new string[] { "one", "three" }; + responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", ["myotherlist", "0", "-1"]); + expectedResponseArray = ["one", "three"]; Assert.AreEqual(expectedResponseArray, responseArray); } @@ -727,23 +727,23 @@ public async Task CanUseLMoveWithCancellationTokenGC() using var db = TestUtils.GetGarnetClient(); db.Connect(); - await db.ExecuteForStringResultAsync("RPUSH", new string[] { "mylist", "one" }); - await db.ExecuteForStringResultAsync("RPUSH", new string[] { "mylist", "two" }); - await db.ExecuteForStringResultAsync("RPUSH", new string[] { "mylist", "three" }); + await db.ExecuteForStringResultAsync("RPUSH", ["mylist", "one"]); + await db.ExecuteForStringResultAsync("RPUSH", ["mylist", "two"]); + await db.ExecuteForStringResultAsync("RPUSH", ["mylist", "three"]); var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; - var response = await db.ExecuteForStringResultWithCancellationAsync("LMOVE", new string[] { "mylist", "myotherlist", "RIGHT", "LEFT" }, token); + var response = await db.ExecuteForStringResultWithCancellationAsync("LMOVE", ["mylist", "myotherlist", "RIGHT", "LEFT"], token); Assert.AreEqual("three", response); //check contents of mylist sorted set - var responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", new string[] { "mylist", "0", "-1" }); + var responseArray = await db.ExecuteForStringArrayResultAsync("LRANGE", ["mylist", "0", "-1"]); var expectedResponseArray = new string[] { "one", "two" }; Assert.AreEqual(expectedResponseArray, responseArray); //Assert the cancellation is seen tokenSource.Cancel(); - var t = db.ExecuteForStringResultWithCancellationAsync("LMOVE", new string[] { "myotherlist", "myotherlist", "LEFT", "RIGHT" }, tokenSource.Token); + var t = db.ExecuteForStringResultWithCancellationAsync("LMOVE", ["myotherlist", "myotherlist", "LEFT", "RIGHT"], tokenSource.Token); Assert.Throws(() => t.Wait(tokenSource.Token)); tokenSource.Dispose(); @@ -956,7 +956,7 @@ public void ListPushPopStressTest() int keyCount = 10; int ppCount = 100; //string[] keys = new string[keyCount]; - HashSet keys = new(); + HashSet keys = []; for (int i = 0; i < keyCount; i++) while (!keys.Add(r.Next().ToString())) { } diff --git a/test/Garnet.test/RespScanCommandsTests.cs b/test/Garnet.test/RespScanCommandsTests.cs index bd0595f90..5a16a255c 100644 --- a/test/Garnet.test/RespScanCommandsTests.cs +++ b/test/Garnet.test/RespScanCommandsTests.cs @@ -57,26 +57,26 @@ public void SeKeysTest() // one key object at object store db.SortedSetAdd("keyThree", new RedisValue("OneKey"), 1, CommandFlags.None); - var actualResponse = db.Execute("KEYS", new object[] { "key*" }); + var actualResponse = db.Execute("KEYS", ["key*"]); Assert.AreEqual(3, ((RedisResult[])actualResponse).Length); var listKeys = new List((string[])actualResponse); Assert.IsTrue(listKeys.Contains("keyOne")); Assert.IsTrue(listKeys.Contains("keyTwo")); Assert.IsTrue(listKeys.Contains("keyThree")); - actualResponse = db.Execute("KEYS", new object[] { "*other*" }); + actualResponse = db.Execute("KEYS", ["*other*"]); Assert.AreEqual(1, ((RedisResult[])actualResponse).Length); listKeys = new List((string[])actualResponse); Assert.IsTrue(listKeys.Contains("Another")); - actualResponse = db.Execute("KEYS", new object[] { "*simple*" }); + actualResponse = db.Execute("KEYS", ["*simple*"]); Assert.AreEqual(0, ((RedisResult[])actualResponse).Length); - actualResponse = db.Execute("KEYS", new object[] { "key??" }); + actualResponse = db.Execute("KEYS", ["key??"]); Assert.AreEqual(0, ((RedisResult[])actualResponse).Length); - actualResponse = db.Execute("KEYS", new object[] { "*" }); + actualResponse = db.Execute("KEYS", ["*"]); Assert.AreEqual(4, ((RedisResult[])actualResponse).Length); } @@ -88,37 +88,37 @@ public void CanDoMemoryUsage() // add keys in both stores db.StringSet(new RedisKey("keyOne"), new RedisValue("valueone")); - db.SortedSetAdd(new RedisKey("myss"), new SortedSetEntry[] { new SortedSetEntry("a", 1) }); - db.ListLeftPush(new RedisKey("mylist"), new RedisValue[] { new RedisValue("1") }); + db.SortedSetAdd(new RedisKey("myss"), [new SortedSetEntry("a", 1)]); + db.ListLeftPush(new RedisKey("mylist"), [new RedisValue("1")]); db.SetAdd(new RedisKey("myset"), new RedisValue("elementone")); - db.HashSet(new RedisKey("myhash"), new HashEntry[] { new HashEntry("a", "1") }); + db.HashSet(new RedisKey("myhash"), [new HashEntry("a", "1")]); - string[] data = new string[] { "a", "b", "c", "d", "e", "f" }; + string[] data = ["a", "b", "c", "d", "e", "f"]; string key = "hllKey"; for (int i = 0; i < data.Length; i++) { db.HyperLogLogAdd(key, data[i]); } - var r = db.Execute("MEMORY", new object[] { "USAGE", "keyOne" }); + var r = db.Execute("MEMORY", ["USAGE", "keyOne"]); Assert.AreEqual("40", r.ToString()); - r = db.Execute("MEMORY", new object[] { "USAGE", "myss" }); + r = db.Execute("MEMORY", ["USAGE", "myss"]); Assert.AreEqual("344", r.ToString()); - r = db.Execute("MEMORY", new object[] { "USAGE", "mylist" }); + r = db.Execute("MEMORY", ["USAGE", "mylist"]); Assert.AreEqual("176", r.ToString()); - r = db.Execute("MEMORY", new object[] { "USAGE", "myset" }); + r = db.Execute("MEMORY", ["USAGE", "myset"]); Assert.AreEqual("200", r.ToString()); - r = db.Execute("MEMORY", new object[] { "USAGE", "myhash" }); + r = db.Execute("MEMORY", ["USAGE", "myhash"]); Assert.AreEqual("264", r.ToString()); - r = db.Execute("MEMORY", new object[] { "USAGE", "foo" }); + r = db.Execute("MEMORY", ["USAGE", "foo"]); Assert.IsTrue(r.IsNull); - r = db.Execute("MEMORY", new object[] { "USAGE", "hllKey" }); + r = db.Execute("MEMORY", ["USAGE", "hllKey"]); Assert.AreEqual("304", r.ToString()); } @@ -131,24 +131,24 @@ public void CanGetKeyType() // add keys in both stores db.StringSet(new RedisKey("keyOne"), new RedisValue("valueone")); - db.SortedSetAdd(new RedisKey("myss"), new SortedSetEntry[] { new SortedSetEntry("a", 1) }); - db.ListLeftPush(new RedisKey("mylist"), new RedisValue[] { new RedisValue("1") }); + db.SortedSetAdd(new RedisKey("myss"), [new SortedSetEntry("a", 1)]); + db.ListLeftPush(new RedisKey("mylist"), [new RedisValue("1")]); db.SetAdd(new RedisKey("myset"), new RedisValue("elementone")); - db.HashSet(new RedisKey("myhash"), new HashEntry[] { new HashEntry("a", "1") }); + db.HashSet(new RedisKey("myhash"), [new HashEntry("a", "1")]); - var r = db.Execute("TYPE", new object[] { "keyOne" }); + var r = db.Execute("TYPE", ["keyOne"]); Assert.IsTrue(r.ToString() == "string"); - r = db.Execute("TYPE", new object[] { "myss" }); + r = db.Execute("TYPE", ["myss"]); Assert.IsTrue(r.ToString() == "zset"); - r = db.Execute("TYPE", new object[] { "mylist" }); + r = db.Execute("TYPE", ["mylist"]); Assert.IsTrue(r.ToString() == "list"); - r = db.Execute("TYPE", new object[] { "myset" }); + r = db.Execute("TYPE", ["myset"]); Assert.IsTrue(r.ToString() == "set"); - r = db.Execute("TYPE", new object[] { "myhash" }); + r = db.Execute("TYPE", ["myhash"]); Assert.IsTrue(r.ToString() == "hash"); } @@ -169,7 +169,7 @@ public void CanUsePatternsInKeysTest() db.StringSet(new RedisKey("hllo"), new RedisValue("four")); - var actualResponse = db.Execute("KEYS", new object[] { "h?llo" }); + var actualResponse = db.Execute("KEYS", ["h?llo"]); Assert.AreEqual(3, ((RedisResult[])actualResponse).Length); var listKeys = new List((string[])actualResponse); Assert.IsTrue(listKeys.Contains("hello")); @@ -177,7 +177,7 @@ public void CanUsePatternsInKeysTest() Assert.IsTrue(listKeys.Contains("hxllo")); - actualResponse = db.Execute("KEYS", new object[] { "h*llo" }); + actualResponse = db.Execute("KEYS", ["h*llo"]); Assert.AreEqual(4, ((RedisResult[])actualResponse).Length); listKeys = new List((string[])actualResponse); Assert.IsTrue(listKeys.Contains("hllo")); @@ -185,19 +185,19 @@ public void CanUsePatternsInKeysTest() Assert.IsTrue(listKeys.Contains("hxllo")); Assert.IsTrue(listKeys.Contains("hello")); - actualResponse = db.Execute("KEYS", new object[] { "h[ae]llo" }); + actualResponse = db.Execute("KEYS", ["h[ae]llo"]); Assert.AreEqual(2, ((RedisResult[])actualResponse).Length); listKeys = new List((string[])actualResponse); Assert.IsTrue(listKeys.Contains("hallo")); Assert.IsTrue(listKeys.Contains("hello")); - actualResponse = db.Execute("KEYS", new object[] { "h[^e]llo" }); + actualResponse = db.Execute("KEYS", ["h[^e]llo"]); Assert.AreEqual(2, ((RedisResult[])actualResponse).Length); listKeys = new List((string[])actualResponse); Assert.IsTrue(listKeys.Contains("hallo")); Assert.IsTrue(listKeys.Contains("hxllo")); - actualResponse = db.Execute("KEYS", new object[] { "h[a-b]llo" }); + actualResponse = db.Execute("KEYS", ["h[a-b]llo"]); Assert.AreEqual(1, ((RedisResult[])actualResponse).Length); listKeys = new List((string[])actualResponse); Assert.IsTrue(listKeys.Contains("hallo")); @@ -212,7 +212,7 @@ public void SeKeysPatternTest() db.StringSet(new RedisKey("keyone"), new RedisValue("valueone")); db.StringSet(new RedisKey("keytwo"), new RedisValue("valuetwo")); db.StringSet(new RedisKey("keythree"), new RedisValue("valuethree")); - var actualResponse = db.Execute("KEYS", new object[] { "*" }); + var actualResponse = db.Execute("KEYS", ["*"]); Assert.AreEqual(3, ((RedisResult[])actualResponse).Length); } @@ -227,16 +227,16 @@ public void SeKeysPatternMatchingTest() db.StringSet(new RedisKey(@"he\*\*foo"), new RedisValue("keyvaluethree")); db.StringSet(new RedisKey(@"he**foo"), new RedisValue("keyvaluefour")); - var actualResponse = db.Execute("KEYS", new object[] { @"he\*\*" }); + var actualResponse = db.Execute("KEYS", [@"he\*\*"]); Assert.AreEqual(1, ((RedisResult[])actualResponse).Length); Assert.IsTrue(String.Equals(@"he**", (((RedisResult[])actualResponse)[0]).ToString())); - actualResponse = db.Execute("KEYS", new object[] { @"he\\*\\*" }); + actualResponse = db.Execute("KEYS", [@"he\\*\\*"]); Assert.AreEqual(2, ((RedisResult[])actualResponse).Length); Assert.IsTrue(String.Equals(@"he\*\*", (((RedisResult[])actualResponse)[0]).ToString())); Assert.IsTrue(String.Equals(@"he\*\*foo", (((RedisResult[])actualResponse)[1]).ToString())); - actualResponse = db.Execute("KEYS", new object[] { @"he**" }); + actualResponse = db.Execute("KEYS", [@"he**"]); Assert.AreEqual(4, ((RedisResult[])actualResponse).Length); } @@ -248,21 +248,21 @@ public void SeKeysPatternMatchingTestVerbatim() db.StringSet(new RedisKey("he**"), new RedisValue("keyvalueone")); db.StringSet(new RedisKey(@"he**foo"), new RedisValue("keyvaluetwo")); - var actualResponse = db.Execute("KEYS", new object[] { @"he\*\*" }); + var actualResponse = db.Execute("KEYS", [@"he\*\*"]); Assert.AreEqual(1, ((RedisResult[])actualResponse).Length); Assert.IsTrue(String.Equals(@"he**", (((RedisResult[])actualResponse)[0]).ToString())); - actualResponse = db.Execute("KEYS", new object[] { @"he\\*\\*" }); + actualResponse = db.Execute("KEYS", [@"he\\*\\*"]); Assert.AreEqual(0, ((RedisResult[])actualResponse).Length); db.StringSet(new RedisKey(@"\\bar"), new RedisValue("secondvalue")); - actualResponse = db.Execute("KEYS", new object[] { @"\\bar" }); + actualResponse = db.Execute("KEYS", [@"\\bar"]); Assert.AreEqual(0, ((RedisResult[])actualResponse).Length); - actualResponse = db.Execute("KEYS", new object[] { @"\\\bar" }); + actualResponse = db.Execute("KEYS", [@"\\\bar"]); Assert.AreEqual(0, ((RedisResult[])actualResponse).Length); - actualResponse = db.Execute("KEYS", new object[] { @"\\\\bar" }); + actualResponse = db.Execute("KEYS", [@"\\\\bar"]); Assert.AreEqual(1, ((RedisResult[])actualResponse).Length); Assert.IsTrue(String.Equals(@"\\bar", (((RedisResult[])actualResponse)[0]).ToString())); } @@ -401,7 +401,7 @@ public void CanUseScanKeysCountAndTypeWithObjects() for (int i = 0; i < 10; i++) { - db.HashSet(new RedisKey($"hskey:{i}"), new HashEntry[] { new HashEntry("field1", "1") }); + db.HashSet(new RedisKey($"hskey:{i}"), [new HashEntry("field1", "1")]); } for (int i = 0; i < 10; i++) @@ -453,12 +453,12 @@ public void CanUseScanKeysAndObjects() for (int i = 0; i < nKeys; i++) { - db.HashSet(new RedisKey($"hskey:{i}"), new HashEntry[] { new HashEntry("field1", "1") }); + db.HashSet(new RedisKey($"hskey:{i}"), [new HashEntry("field1", "1")]); } for (int i = 0; i < nKeys; i++) { - db.SortedSetAdd(new RedisKey($"sskey:{i}"), new SortedSetEntry[] { new SortedSetEntry("a", 1) }); + db.SortedSetAdd(new RedisKey($"sskey:{i}"), [new SortedSetEntry("a", 1)]); } int cursor = 0; @@ -490,7 +490,7 @@ public void CanUseScanKeysTypeAndMatch() for (int i = 0; i < nKeys; i++) { - db.HashSet(new RedisKey($"hskey:{i}"), new HashEntry[] { new HashEntry("field1", "1") }); + db.HashSet(new RedisKey($"hskey:{i}"), [new HashEntry("field1", "1")]); } int cursor = 0; diff --git a/test/Garnet.test/RespSetTest.cs b/test/Garnet.test/RespSetTest.cs index 8d69d8f91..3c9bb6506 100644 --- a/test/Garnet.test/RespSetTest.cs +++ b/test/Garnet.test/RespSetTest.cs @@ -41,7 +41,7 @@ public void CanAddAndListMembers() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - var result = db.SetAdd(new RedisKey("user1:set"), new RedisValue[] { "Hello", "World", "World" }); + var result = db.SetAdd(new RedisKey("user1:set"), ["Hello", "World", "World"]); Assert.AreEqual(2, result); var members = db.SetMembers(new RedisKey("user1:set")); @@ -62,7 +62,7 @@ public void CanCheckIfMemberExistsInSet() db.KeyDelete(key); - db.SetAdd(key, new RedisValue[] { "Hello", "World" }); + db.SetAdd(key, ["Hello", "World"]); var existingMemberExists = db.SetContains(key, "Hello"); Assert.IsTrue(existingMemberExists); @@ -117,7 +117,7 @@ public void CanRemoveField() { using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - var result = db.SetAdd(new RedisKey("user1:set"), new RedisValue[] { "ItemOne", "ItemTwo", "ItemThree", "ItemFour" }); + var result = db.SetAdd(new RedisKey("user1:set"), ["ItemOne", "ItemTwo", "ItemThree", "ItemFour"]); Assert.AreEqual(4, result); var existingMemberExists = db.SetContains(new RedisKey("user1:set"), "ItemOne"); @@ -144,7 +144,7 @@ public void CanRemoveField() expectedResponse = 352; Assert.AreEqual(expectedResponse, actualValue); - var longResponse = db.SetRemove(new RedisKey("user1:set"), new RedisValue[] { "ItemTwo", "ItemThree" }); + var longResponse = db.SetRemove(new RedisKey("user1:set"), ["ItemTwo", "ItemThree"]); Assert.AreEqual(2, longResponse); memresponse = db.Execute("MEMORY", "USAGE", "user1:set"); @@ -166,7 +166,7 @@ public void CanUseSScanNoParameters() var items = db.SetScan(new RedisKey("foo"), new RedisValue("*"), pageSize: 10); Assert.IsEmpty(items, "Failed to use SetScan on non existing key"); - RedisValue[] entries = new RedisValue[] { "item-a", "item-b", "item-c", "item-d", "item-e", "item-aaa" }; + RedisValue[] entries = ["item-a", "item-b", "item-c", "item-d", "item-e", "item-aaa"]; // Add some items var added = db.SetAdd("myset", entries); @@ -195,7 +195,7 @@ public void CanUseSScanWithMatch() var db = redis.GetDatabase(0); // Add some items - var added = db.SetAdd("myset", new RedisValue[] { "aa", "bb", "cc", "dd", "ee", "aaf" }); + var added = db.SetAdd("myset", ["aa", "bb", "cc", "dd", "ee", "aaf"]); Assert.AreEqual(6, added); var members = db.SetScan(new RedisKey("myset"), new RedisValue("*aa")); @@ -284,30 +284,30 @@ public void CanDoSetUnion() var result = db.SetAdd(new RedisKey("key1"), redisValues1); Assert.AreEqual(4, result); - result = db.SetAdd(new RedisKey("key2"), new RedisValue[] { "item-c" }); + result = db.SetAdd(new RedisKey("key2"), ["item-c"]); Assert.AreEqual(1, result); - result = db.SetAdd(new RedisKey("key3"), new RedisValue[] { "item-a", "item-c", "item-e" }); + result = db.SetAdd(new RedisKey("key3"), ["item-a", "item-c", "item-e"]); Assert.AreEqual(3, result); - var members = db.SetCombine(SetOperation.Union, new RedisKey[] { "key1", "key2", "key3" }); - RedisValue[] entries = new RedisValue[] { "item-a", "item-b", "item-c", "item-d", "item-e" }; + var members = db.SetCombine(SetOperation.Union, ["key1", "key2", "key3"]); + RedisValue[] entries = ["item-a", "item-b", "item-c", "item-d", "item-e"]; Assert.AreEqual(5, members.Length); // assert two arrays are equal ignoring order Assert.IsTrue(members.OrderBy(x => x).SequenceEqual(entries.OrderBy(x => x))); - members = db.SetCombine(SetOperation.Union, new RedisKey[] { "key1", "key2", "key3", "_not_exists" }); + members = db.SetCombine(SetOperation.Union, ["key1", "key2", "key3", "_not_exists"]); Assert.AreEqual(5, members.Length); Assert.IsTrue(members.OrderBy(x => x).SequenceEqual(entries.OrderBy(x => x))); - members = db.SetCombine(SetOperation.Union, new RedisKey[] { "_not_exists_1", "_not_exists_2", "_not_exists_3" }); + members = db.SetCombine(SetOperation.Union, ["_not_exists_1", "_not_exists_2", "_not_exists_3"]); Assert.IsEmpty(members); - members = db.SetCombine(SetOperation.Union, new RedisKey[] { "_not_exists_1", "key1", "_not_exists_2", "_not_exists_3" }); + members = db.SetCombine(SetOperation.Union, ["_not_exists_1", "key1", "_not_exists_2", "_not_exists_3"]); Assert.AreEqual(4, members.Length); Assert.IsTrue(members.OrderBy(x => x).SequenceEqual(redisValues1.OrderBy(x => x))); - members = db.SetCombine(SetOperation.Union, new RedisKey[] { "key1", "key2" }); + members = db.SetCombine(SetOperation.Union, ["key1", "key2"]); Assert.AreEqual(4, members.Length); Assert.IsTrue(members.OrderBy(x => x).SequenceEqual(redisValues1.OrderBy(x => x))); @@ -589,12 +589,14 @@ public void CanDoSRANDMEMBERWithCountCommandLC() [Test] public void CanDoSPOPCommandLC() { - var myset = new HashSet(); - myset.Add("one"); - myset.Add("two"); - myset.Add("three"); - myset.Add("four"); - myset.Add("five"); + var myset = new HashSet + { + "one", + "two", + "three", + "four", + "five" + }; CreateLongSet(); @@ -754,34 +756,34 @@ public async Task CanDoSMOVECommandGC() db.Connect(); //If set doesn't exist, then return 0. - var response = await db.ExecuteForLongResultAsync("SMOVE", new string[] { "sourceSet", "destinationSet", "value" }); + var response = await db.ExecuteForLongResultAsync("SMOVE", ["sourceSet", "destinationSet", "value"]); Assert.AreEqual(response, 0); - await db.ExecuteForStringResultAsync("SADD", new string[] { "sourceSet", "sourceValue", "commonValue" }); - await db.ExecuteForStringResultAsync("SADD", new string[] { "destinationSet", "destinationValue", "commonValue" }); + await db.ExecuteForStringResultAsync("SADD", ["sourceSet", "sourceValue", "commonValue"]); + await db.ExecuteForStringResultAsync("SADD", ["destinationSet", "destinationValue", "commonValue"]); //Same key. - response = await db.ExecuteForLongResultAsync("SMOVE", new string[] { "sourceSet", "sourceSet", "sourceValue" }); + response = await db.ExecuteForLongResultAsync("SMOVE", ["sourceSet", "sourceSet", "sourceValue"]); Assert.AreEqual(response, 0); //Move non-common member. - response = await db.ExecuteForLongResultAsync("SMOVE", new string[] { "sourceSet", "destinationSet", "sourceValue" }); + response = await db.ExecuteForLongResultAsync("SMOVE", ["sourceSet", "destinationSet", "sourceValue"]); Assert.AreEqual(response, 1); - Assert.AreEqual(await db.ExecuteForLongResultAsync("SCARD", new string[] { "sourceSet" }), 1); - Assert.AreEqual(await db.ExecuteForLongResultAsync("SCARD", new string[] { "destinationSet" }), 3); + Assert.AreEqual(await db.ExecuteForLongResultAsync("SCARD", ["sourceSet"]), 1); + Assert.AreEqual(await db.ExecuteForLongResultAsync("SCARD", ["destinationSet"]), 3); - var sourceSetMembers = await db.ExecuteForStringArrayResultAsync("SMEMBERS", new string[] { "sourceSet" }); - var destinationSetMembers = await db.ExecuteForStringArrayResultAsync("SMEMBERS", new string[] { "destinationSet" }); + var sourceSetMembers = await db.ExecuteForStringArrayResultAsync("SMEMBERS", ["sourceSet"]); + var destinationSetMembers = await db.ExecuteForStringArrayResultAsync("SMEMBERS", ["destinationSet"]); Assert.IsFalse(sourceSetMembers.Contains("sourceValue")); Assert.IsTrue(destinationSetMembers.Contains("sourceValue")); //Move common member. - response = await db.ExecuteForLongResultAsync("SMOVE", new string[] { "sourceSet", "destinationSet", "commonValue" }); + response = await db.ExecuteForLongResultAsync("SMOVE", ["sourceSet", "destinationSet", "commonValue"]); Assert.AreEqual(response, 1); - Assert.AreEqual(await db.ExecuteForLongResultAsync("SCARD", new string[] { "sourceSet" }), 0); - Assert.AreEqual(await db.ExecuteForLongResultAsync("SCARD", new string[] { "destinationSet" }), 3); + Assert.AreEqual(await db.ExecuteForLongResultAsync("SCARD", ["sourceSet"]), 0); + Assert.AreEqual(await db.ExecuteForLongResultAsync("SCARD", ["destinationSet"]), 3); - sourceSetMembers = await db.ExecuteForStringArrayResultAsync("SMEMBERS", new string[] { "sourceSet" }); - destinationSetMembers = await db.ExecuteForStringArrayResultAsync("SMEMBERS", new string[] { "destinationSet" }); + sourceSetMembers = await db.ExecuteForStringArrayResultAsync("SMEMBERS", ["sourceSet"]); + destinationSetMembers = await db.ExecuteForStringArrayResultAsync("SMEMBERS", ["destinationSet"]); Assert.IsFalse(sourceSetMembers.Contains("commonValue")); Assert.IsTrue(destinationSetMembers.Contains("commonValue")); } diff --git a/test/Garnet.test/RespSortedSetGarnetClientTests.cs b/test/Garnet.test/RespSortedSetGarnetClientTests.cs index c875a2111..6d7f2bb34 100644 --- a/test/Garnet.test/RespSortedSetGarnetClientTests.cs +++ b/test/Garnet.test/RespSortedSetGarnetClientTests.cs @@ -24,19 +24,19 @@ public class RespSortedSetGarnetClientTests ManualResetEventSlim waiter; const int maxIterations = 3; - static readonly SortedSetEntry[] leaderBoard = new SortedSetEntry[] - { + static readonly SortedSetEntry[] leaderBoard = + [ new SortedSetEntry("Dave", 340), - new SortedSetEntry("Kendra", 400), - new SortedSetEntry("Tom", 560), - new SortedSetEntry("Barbara", 650), - new SortedSetEntry("Jennifer", 690), - new SortedSetEntry("Peter", 690), - new SortedSetEntry("Frank", 740), - new SortedSetEntry("Lester", 790), - new SortedSetEntry("Alice", 850), - new SortedSetEntry("Mary", 980) - }; + new SortedSetEntry("Kendra", 400), + new SortedSetEntry("Tom", 560), + new SortedSetEntry("Barbara", 650), + new SortedSetEntry("Jennifer", 690), + new SortedSetEntry("Peter", 690), + new SortedSetEntry("Frank", 740), + new SortedSetEntry("Lester", 790), + new SortedSetEntry("Alice", 850), + new SortedSetEntry("Mary", 980) + ]; [SetUp] @@ -65,10 +65,10 @@ public async Task CanDoZAddGarnetAsync() using var db = new GarnetClient(TestUtils.Address, TestUtils.Port); db.Connect(); - List parameters = new() - { + List parameters = + [ "leaderboard" - }; + ]; foreach (SortedSetEntry item in leaderBoard) { @@ -94,8 +94,7 @@ public void CanDoZAddGarnetCallback() { using var db = new GarnetClient(TestUtils.Address, TestUtils.Port); db.Connect(); - List parameters = new(); - parameters.AddRange(new string[] { "myzset1", "1", "KEY1", "2", "KEY2" }); + List parameters = ["myzset1", "1", "KEY1", "2", "KEY2"]; db.ExecuteForMemoryResult(SimpleMemoryResultCallback, 1, "ZADD", parameters); waiter.Wait(); waiter.Reset(); @@ -107,8 +106,7 @@ public void CanDoExecuteForStringResultCallback() using var db = new GarnetClient(TestUtils.Address, TestUtils.Port); db.Connect(); var expectedResult = "2"; - List parameters = new(); - parameters.AddRange(new string[] { "myzset1", "1", "KEY1", "2", "KEY2" }); + List parameters = ["myzset1", "1", "KEY1", "2", "KEY2"]; db.ExecuteForStringResult((c, s) => { Assert.IsTrue(s == expectedResult); waiter.Set(); @@ -133,8 +131,7 @@ public async Task CanDoZCardGarnetUsingMemoryResultAsync() { using var db = new GarnetClient(TestUtils.Address, TestUtils.Port); db.Connect(); - List parameters = new(); - parameters.AddRange(new string[] { "myzset1", "1", "KEY1", "2", "KEY2" }); + List parameters = ["myzset1", "1", "KEY1", "2", "KEY2"]; db.ExecuteForMemoryResult(SimpleMemoryResultCallback, 1, "ZADD", parameters); waiter.Wait(); waiter.Reset(); @@ -179,10 +176,10 @@ public async Task CanDoZAddGarnetMultithread() Assert.Fail("Concurrency issue, review test: CanDoZaddGarnetMultithread"); } - List parameters = new() - { + List parameters = + [ name - }; + ]; foreach (SortedSetEntry item in leaderBoard) { parameters.Add(item.Score.ToString(CultureInfo.InvariantCulture)); @@ -192,8 +189,7 @@ public async Task CanDoZAddGarnetMultithread() await db.ExecuteForMemoryResultAsync("ZADD", parameters); await Task.Delay(millisecondsDelay: rnd.Next(10, 50)); - parameters = new List(); - parameters.AddRange(new string[] { name, "-inf", "+inf" }); + parameters = [name, "-inf", "+inf"]; var result = await db.ExecuteForMemoryResultArrayAsync("ZRANGEBYSCORE", parameters); @@ -238,10 +234,10 @@ public async Task CanUseExecuteForStringArrayResult() using var db = new GarnetClient(TestUtils.Address, TestUtils.Port); db.Connect(); - List parameters = new() - { + List parameters = + [ "leaderboard" - }; + ]; foreach (SortedSetEntry item in leaderBoard) { @@ -251,8 +247,7 @@ public async Task CanUseExecuteForStringArrayResult() await db.ExecuteForMemoryResultAsync("ZADD", parameters); - parameters = new List(); - parameters.AddRange(new string[] { "leaderboard", "-inf", "+inf" }); + parameters = ["leaderboard", "-inf", "+inf"]; var result = await db.ExecuteForStringArrayResultAsync("ZRANGEBYSCORE", parameters); // assert the elements @@ -268,9 +263,8 @@ public async Task CanUseExecuteForStringResultAsync() { using var db = new GarnetClient(TestUtils.Address, TestUtils.Port); db.Connect(); - List parameters = new(); - parameters = new List(); - parameters.AddRange(new string[] { "myzset1", "1", "KEY1", "2", "KEY2" }); + List parameters = []; + parameters = ["myzset1", "1", "KEY1", "2", "KEY2"]; var result = await db.ExecuteForStringResultAsync("ZADD", parameters); Assert.AreEqual("2", result); @@ -291,10 +285,10 @@ public async Task CanUseExecuteForMemoryResultArrayWithCancellationTokenAsync() using var db = new GarnetClient(TestUtils.Address, TestUtils.Port); db.Connect(); - List parameters = new() - { + List parameters = + [ "leaderboard" - }; + ]; foreach (SortedSetEntry item in leaderBoard) { @@ -307,8 +301,7 @@ public async Task CanUseExecuteForMemoryResultArrayWithCancellationTokenAsync() var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; - parameters = new List(); - parameters.AddRange(new string[] { "leaderboard", "-inf", "+inf" }); + parameters = ["leaderboard", "-inf", "+inf"]; var t = db.ExecuteForMemoryResultArrayWithCancellationAsync("ZRANGEBYSCORE", parameters, token); var result = t.GetAwaiter().GetResult(); Assert.IsTrue(t.IsCompletedSuccessfully); @@ -332,10 +325,10 @@ public async Task CanUseExecuteForMemoryResultWithCancellationTokenAsync() using var db = new GarnetClient(TestUtils.Address, TestUtils.Port); db.Connect(); - List parameters = new() - { + List parameters = + [ "leaderboard" - }; + ]; foreach (SortedSetEntry item in leaderBoard) { @@ -378,7 +371,7 @@ private static async Task DoZRangeAsync(int taskId, CancellationToken ct) db.Connect(); var parameters = new List(); - parameters.AddRange(new string[] { "leaderboard", "-inf", "+inf" }); + parameters.AddRange(["leaderboard", "-inf", "+inf"]); for (int i = 0; i <= maxIterations; i++) { @@ -517,10 +510,10 @@ public async Task CanGarnetClientUseZCard() Assert.AreEqual(expectedValue, len); // add a new Sorted Set - List parameters = new() - { + List parameters = + [ "leaderboard" - }; + ]; foreach (SortedSetEntry item in leaderBoard) { diff --git a/test/Garnet.test/RespSortedSetGeoTests.cs b/test/Garnet.test/RespSortedSetGeoTests.cs index d43d1e971..9c2c45692 100644 --- a/test/Garnet.test/RespSortedSetGeoTests.cs +++ b/test/Garnet.test/RespSortedSetGeoTests.cs @@ -195,7 +195,7 @@ public void CanUseGeoPos() using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); db.GeoAdd(new RedisKey("Sicily"), 13.361389, 38.115556, new RedisValue("Palermo"), CommandFlags.None); - var response = db.GeoPosition(new RedisKey("Sicily"), new RedisValue[] { "Palermo", "Unknown" }); + var response = db.GeoPosition(new RedisKey("Sicily"), ["Palermo", "Unknown"]); Assert.AreEqual(2, response.Length); Assert.AreEqual(default(GeoPosition), response[1]); @@ -205,7 +205,7 @@ public void CanUseGeoPos() Assert.AreEqual(expectedResponse, actualValue); db.GeoAdd(new RedisKey("SecondKey"), 13.361389, 38.115556, new RedisValue("Palermo")); - response = db.GeoPosition(new RedisKey("SecondKey"), new RedisValue[] { "Palermo" }); + response = db.GeoPosition(new RedisKey("SecondKey"), ["Palermo"]); Assert.AreEqual(1, response.Length); Assert.IsNotNull(response[0]); @@ -214,7 +214,7 @@ public void CanUseGeoPos() expectedResponse = 352; Assert.AreEqual(expectedResponse, actualValue); - var responseHash = db.GeoHash(new RedisKey("SecondKey"), new RedisValue[] { "Palermo" }); + var responseHash = db.GeoHash(new RedisKey("SecondKey"), ["Palermo"]); Assert.AreEqual(1, responseHash.Length); Assert.AreEqual("sqc8b49rnyt", responseHash[0]); diff --git a/test/Garnet.test/RespSortedSetTests.cs b/test/Garnet.test/RespSortedSetTests.cs index 5ae082998..29772cb31 100644 --- a/test/Garnet.test/RespSortedSetTests.cs +++ b/test/Garnet.test/RespSortedSetTests.cs @@ -18,36 +18,36 @@ public class RespSortedSetTests { protected GarnetServer server; - static readonly SortedSetEntry[] entries = new SortedSetEntry[] - { + static readonly SortedSetEntry[] entries = + [ new SortedSetEntry("a", 1), - new SortedSetEntry("b", 2), - new SortedSetEntry("c", 3), - new SortedSetEntry("d", 4), - new SortedSetEntry("e", 5), - new SortedSetEntry("f", 6), - new SortedSetEntry("g", 7), - new SortedSetEntry("h", 8), - new SortedSetEntry("i", 9), - new SortedSetEntry("j", 10) - }; - - static readonly SortedSetEntry[] leaderBoard = new SortedSetEntry[] - { + new SortedSetEntry("b", 2), + new SortedSetEntry("c", 3), + new SortedSetEntry("d", 4), + new SortedSetEntry("e", 5), + new SortedSetEntry("f", 6), + new SortedSetEntry("g", 7), + new SortedSetEntry("h", 8), + new SortedSetEntry("i", 9), + new SortedSetEntry("j", 10) + ]; + + static readonly SortedSetEntry[] leaderBoard = + [ new SortedSetEntry("Dave", 340), - new SortedSetEntry("Kendra", 400), - new SortedSetEntry("Tom", 560), - new SortedSetEntry("Barbara", 650), - new SortedSetEntry("Jennifer", 690), - new SortedSetEntry("Peter", 690), - new SortedSetEntry("Frank", 740), - new SortedSetEntry("Lester", 790), - new SortedSetEntry("Alice", 850), - new SortedSetEntry("Mary", 980) - }; - - static readonly SortedSetEntry[] powOfTwo = new SortedSetEntry[] - { + new SortedSetEntry("Kendra", 400), + new SortedSetEntry("Tom", 560), + new SortedSetEntry("Barbara", 650), + new SortedSetEntry("Jennifer", 690), + new SortedSetEntry("Peter", 690), + new SortedSetEntry("Frank", 740), + new SortedSetEntry("Lester", 790), + new SortedSetEntry("Alice", 850), + new SortedSetEntry("Mary", 980) + ]; + + static readonly SortedSetEntry[] powOfTwo = + [ new SortedSetEntry("a", 1), new SortedSetEntry("b", 2), new SortedSetEntry("c", 4), @@ -58,7 +58,7 @@ public class RespSortedSetTests new SortedSetEntry("h", 128), new SortedSetEntry("i", 256), new SortedSetEntry("j", 512) - }; + ]; [SetUp] @@ -124,7 +124,7 @@ public void AddAndLength() card = db.SortedSetLength(key); Assert.AreEqual(entries2.Length, card); - added = db.SortedSetAdd(key, new[] { new SortedSetEntry("a", 12) }); + added = db.SortedSetAdd(key, [new SortedSetEntry("a", 12)]); Assert.AreEqual(0, added); response = db.Execute("MEMORY", "USAGE", key); @@ -685,14 +685,16 @@ public async Task CanManageZRangeByScoreWhenStartHigherThanExistingMaxScoreSE() [Test] public void CanHaveEqualScores() { - SortedSet<(double, byte[])> sortedSet = new(new SortedSetComparer()); - sortedSet.Add((340, Encoding.ASCII.GetBytes("Dave"))); - sortedSet.Add((400, Encoding.ASCII.GetBytes("Kendra"))); - sortedSet.Add((560, Encoding.ASCII.GetBytes("Tom"))); - sortedSet.Add((650, Encoding.ASCII.GetBytes("Barbara"))); - sortedSet.Add((690, Encoding.ASCII.GetBytes("Jennifer"))); - sortedSet.Add((690, Encoding.ASCII.GetBytes("Peter"))); - sortedSet.Add((740, Encoding.ASCII.GetBytes("Frank"))); + SortedSet<(double, byte[])> sortedSet = new(new SortedSetComparer()) + { + (340, Encoding.ASCII.GetBytes("Dave")), + (400, Encoding.ASCII.GetBytes("Kendra")), + (560, Encoding.ASCII.GetBytes("Tom")), + (650, Encoding.ASCII.GetBytes("Barbara")), + (690, Encoding.ASCII.GetBytes("Jennifer")), + (690, Encoding.ASCII.GetBytes("Peter")), + (740, Encoding.ASCII.GetBytes("Frank")) + }; var c = sortedSet.Count; Assert.AreEqual(7, c); diff --git a/test/Garnet.test/RespTests.cs b/test/Garnet.test/RespTests.cs index ff984636e..935a9fa43 100644 --- a/test/Garnet.test/RespTests.cs +++ b/test/Garnet.test/RespTests.cs @@ -767,7 +767,7 @@ public void SingleDeleteWithObjectStoreDisable_LTM() int valLen = 256; int keyLen = 8; - List> data = new(); + List> data = []; for (int i = 0; i < keyCount; i++) { data.Add(new Tuple(GetRandomString(keyLen), GetRandomString(valLen))); @@ -810,7 +810,7 @@ public void MultiKeyDelete([Values] bool withoutObjectStore) int valLen = 16; int keyLen = 8; - List> data = new(); + List> data = []; for (int i = 0; i < keyCount; i++) { data.Add(new Tuple(GetRandomString(keyLen), GetRandomString(valLen))); @@ -838,7 +838,7 @@ public void MultiKeyDeleteObjectStore() int valLen = 16; int keyLen = 8; - List keys = new(); + List keys = []; for (int i = 0; i < keyCount; i++) { keys.Add(GetRandomString(keyLen)); @@ -878,7 +878,7 @@ public void MultiKeyUnlink([Values] bool withoutObjectStore) int valLen = 16; int keyLen = 8; - List> data = new(); + List> data = []; for (int i = 0; i < keyCount; i++) { data.Add(new Tuple(GetRandomString(keyLen), GetRandomString(valLen))); @@ -905,7 +905,7 @@ public void MultiKeyUnlinkObjectStore() int valLen = 16; int keyLen = 8; - List keys = new(); + List keys = []; for (int i = 0; i < keyCount; i++) { keys.Add(GetRandomString(keyLen)); @@ -973,15 +973,15 @@ public void MultipleExistsKeysAndObjects() using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig()); var db = redis.GetDatabase(0); - var count = db.ListLeftPush("listKey", new RedisValue[] { "a", "b", "c", "d" }); + var count = db.ListLeftPush("listKey", ["a", "b", "c", "d"]); Assert.AreEqual(4, count); - var zaddItems = db.SortedSetAdd("zset:test", new SortedSetEntry[] { new SortedSetEntry("a", 1), new SortedSetEntry("b", 2) }); + var zaddItems = db.SortedSetAdd("zset:test", [new SortedSetEntry("a", 1), new SortedSetEntry("b", 2)]); Assert.AreEqual(2, zaddItems); db.StringSet("foo", "bar"); - var exists = db.KeyExists(new RedisKey[] { "key", "listKey", "zset:test", "foo" }); + var exists = db.KeyExists(["key", "listKey", "zset:test", "foo"]); Assert.AreEqual(3, exists); } @@ -1279,7 +1279,7 @@ public void KeyExpireStringTest(string command) if (command.Equals("EXPIRE")) db.KeyExpire(key, TimeSpan.FromSeconds(1)); else - db.Execute(command, new object[] { key, 1000 }); + db.Execute(command, [key, 1000]); Thread.Sleep(1500); @@ -1296,7 +1296,7 @@ public void KeyExpireObjectTest(string command) var db = redis.GetDatabase(0); var key = "keyA"; - db.SortedSetAdd(key, new SortedSetEntry[] { new SortedSetEntry("element", 1.0) }); + db.SortedSetAdd(key, [new SortedSetEntry("element", 1.0)]); var value = db.SortedSetScore(key, "element"); Assert.AreEqual(1.0, value); @@ -1319,7 +1319,7 @@ public void KeyExpireOptionsTest(string command) var db = redis.GetDatabase(0); var key = "keyA"; - object[] args = new object[] { key, 1000, "" }; + object[] args = [key, 1000, ""]; db.StringSet(key, key); args[2] = "XX";// XX -- Set expiry only when the key has an existing expiry diff --git a/test/Garnet.test/RespTransactionProcTests.cs b/test/Garnet.test/RespTransactionProcTests.cs index 528f7ddf7..4b84349f3 100644 --- a/test/Garnet.test/RespTransactionProcTests.cs +++ b/test/Garnet.test/RespTransactionProcTests.cs @@ -136,7 +136,7 @@ public void TransactionProcSampleDeleteTest() string value = "value100"; double score = 100; - db.SortedSetAdd(sortedSet1key, new SortedSetEntry[] { new SortedSetEntry(value, score) }); + db.SortedSetAdd(sortedSet1key, [new SortedSetEntry(value, score)]); string sortedSetSecondkey = "sortedSetkey2"; string secondValue = "value200"; @@ -229,7 +229,7 @@ public void TransactionSortedSetRemoveProcTest() double score = 100; string value = "value100"; - db.SortedSetAdd(sortedSetKey, new SortedSetEntry[] { new SortedSetEntry(value, score) }); + db.SortedSetAdd(sortedSetKey, [new SortedSetEntry(value, score)]); var result = db.Execute("SORTEDSETREMOVETX", sortedSetKey, value); diff --git a/test/Garnet.test/TestProcedureBitmap.cs b/test/Garnet.test/TestProcedureBitmap.cs index 5a34ae854..b492deef9 100644 --- a/test/Garnet.test/TestProcedureBitmap.cs +++ b/test/Garnet.test/TestProcedureBitmap.cs @@ -46,7 +46,7 @@ public override void Main(TGarnetApi api, ArgSlice input, ref Memory { int offset = 0; bool result = true; - BitmapOperation[] bitwiseOps = new BitmapOperation[] { BitmapOperation.AND, BitmapOperation.OR, BitmapOperation.XOR }; + BitmapOperation[] bitwiseOps = [BitmapOperation.AND, BitmapOperation.OR, BitmapOperation.XOR]; //get paramaters var bitmapA = GetNextArg(input, ref offset); @@ -78,7 +78,7 @@ public override void Main(TGarnetApi api, ArgSlice input, ref Memory api.SET(bitmapA, data); //Not operator - api.StringBitOperation(BitmapOperation.NOT, destinationKeyBitOp, new ArgSlice[] { bitmapA }, out long size); + api.StringBitOperation(BitmapOperation.NOT, destinationKeyBitOp, [bitmapA], out long size); if (size != 8) { result = false; @@ -101,7 +101,7 @@ public override void Main(TGarnetApi api, ArgSlice input, ref Memory //apply operators for (int i = 0; i < bitwiseOps.Length; i++) { - api.StringBitOperation(bitwiseOps[i], destinationKeyBitOp, new ArgSlice[] { bitmapA, bitmapB }, out size); + api.StringBitOperation(bitwiseOps[i], destinationKeyBitOp, [bitmapA, bitmapB], out size); if (size != 8) { result = false; @@ -129,7 +129,7 @@ public override void Main(TGarnetApi api, ArgSlice input, ref Memory } //bitfield command - data = new byte[1] { (byte)'P' }; + data = [(byte)'P']; api.SET(bitmapA, data); var listCommands = new List(); diff --git a/test/Garnet.test/TestProcedureHLL.cs b/test/Garnet.test/TestProcedureHLL.cs index cc329b95d..3564431ba 100644 --- a/test/Garnet.test/TestProcedureHLL.cs +++ b/test/Garnet.test/TestProcedureHLL.cs @@ -49,7 +49,7 @@ public override void Main(TGarnetApi api, ArgSlice input, ref Memory } api.HyperLogLogAdd(hll, elements, out var resultPfAdd); result = resultPfAdd; - api.HyperLogLogLength(new ArgSlice[1] { hll }, out long count); + api.HyperLogLogLength([hll], out long count); if (count != 7) { result = false; diff --git a/test/Garnet.test/TestUtils.cs b/test/Garnet.test/TestUtils.cs index 60aa50c6a..cd34ba7d0 100644 --- a/test/Garnet.test/TestUtils.cs +++ b/test/Garnet.test/TestUtils.cs @@ -548,7 +548,7 @@ public static LightClientRequest CreateRequest(LightClient.OnResponseDelegateUns public static EndPointCollection GetEndPoints(int shards, int port = default) { Port = port == default ? Port : port; - EndPointCollection endPoints = new(); + EndPointCollection endPoints = []; for (int i = 0; i < shards; i++) endPoints.Add(IPAddress.Parse("127.0.0.1"), Port + i); return endPoints;