public async Task Can_AddRangeToSortedSet_and_GetAllFromSet()
        {
            var success = await RedisAsync.AddRangeToSortedSetAsync(SetId, storeMembers, 1);

            Assert.That(success, Is.True);

            var members = await RedisAsync.GetAllItemsFromSortedSetAsync(SetId);

            Assert.That(members, Is.EquivalentTo(storeMembers));
        }
        public async Task Does_SortedSetContainsValue()
        {
            const string existingMember    = "two";
            const string nonExistingMember = "five";

            await storeMembers.ForEachAsync(async x => await RedisAsync.AddItemToSortedSetAsync(SetId, x));

            Assert.That(await RedisAsync.SortedSetContainsItemAsync(SetId, existingMember), Is.True);
            Assert.That(await RedisAsync.SortedSetContainsItemAsync(SetId, nonExistingMember), Is.False);
        }
        public override void OnBeforeEachTest()
        {
            base.OnBeforeEachTest();

            RedisRaw?.Dispose();
            RedisRaw = new RedisClient(TestConfig.SingleHost)
            {
                NamespacePrefix = "RedisTypedClientTests:"
            };
            RedisTyped = RedisAsync.As <CacheRecord>();
        }
        public async Task Can_EvalSha_int()
        {
            var luaBody = "return 3141591";
            await RedisAsync.ExecLuaAsIntAsync(luaBody, Array.Empty <string>());

            var sha1 = await RedisAsync.CalculateSha1Async(luaBody);

            var intVal = await RedisAsync.ExecLuaShaAsIntAsync(sha1, Array.Empty <string>());

            Assert.That(intVal, Is.EqualTo(3141591));
        }
Exemplo n.º 5
0
        public async Task Can_GetHashCount()
        {
            foreach (var x in stringMap)
            {
                await RedisAsync.SetEntryInHashAsync(HashId, x.Key, x.Value);
            }

            var hashCount = await RedisAsync.GetHashCountAsync(HashId);

            Assert.That(hashCount, Is.EqualTo(stringMap.Count));
        }
Exemplo n.º 6
0
        public async Task Can_GetItemFromHash()
        {
            foreach (var x in stringMap)
            {
                await RedisAsync.SetEntryInHashAsync(HashId, x.Key, x.Value);
            }

            var hashValue = await RedisAsync.GetValueFromHashAsync(HashId, "two");

            Assert.That(hashValue, Is.EqualTo(stringMap["two"]));
        }
Exemplo n.º 7
0
        public async Task Can_SetItemInHash_and_GetAllFromHash()
        {
            foreach (var x in stringMap)
            {
                await RedisAsync.SetEntryInHashAsync(HashId, x.Key, x.Value);
            }

            var members = await RedisAsync.GetAllEntriesFromHashAsync(HashId);

            Assert.That(members, Is.EquivalentTo(stringMap));
        }
Exemplo n.º 8
0
        public async Task Can_increment_Hash_field_beyond_32_bits()
        {
            await RedisAsync.SetEntryInHashAsync(HashId, "int", Int32.MaxValue.ToString());

            await RedisAsync.IncrementValueInHashAsync(HashId, "int", 1);

            long actual   = Int64.Parse(await RedisAsync.GetValueFromHashAsync(HashId, "int"));
            long expected = Int32.MaxValue + 1L;

            Assert.That(actual, Is.EqualTo(expected));
        }
Exemplo n.º 9
0
        public async Task Can_Set_and_Get_Config()
        {
            var orig = await RedisAsync.GetConfigAsync("maxmemory");

            var newMaxMemory = (long.Parse(orig) + 1).ToString();
            await RedisAsync.SetConfigAsync("maxmemory", newMaxMemory);

            var current = await RedisAsync.GetConfigAsync("maxmemory");

            Assert.That(current, Is.EqualTo(newMaxMemory));
        }
        public async Task Can_WriteAll()
        {
            await RedisAsync.WriteAllAsync(testModels);

            var testModelIds = testModels.ConvertAll(x => x.Id);

            var allModels = (await RedisAsync.GetByIdsAsync <TestModel>(testModelIds))
                            .OrderBy(x => x.Age).ToList();

            Assert.That(allModels, Is.EquivalentTo(testModels));
        }
Exemplo n.º 11
0
        public async Task Can_PopFromList()
        {
            foreach (var x in storeMembers)
            {
                await RedisAsync.AddItemToListAsync(ListId, x);
            }

            var item4 = await RedisAsync.PopItemFromListAsync(ListId);

            Assert.That(item4, Is.EqualTo("four"));
        }
Exemplo n.º 12
0
        public async Task Can_GetListCount()
        {
            foreach (var x in storeMembers)
            {
                await RedisAsync.AddItemToListAsync(ListId, x);
            }

            var listCount = await RedisAsync.GetListCountAsync(ListId);

            Assert.That(listCount, Is.EqualTo(storeMembers.Count));
        }
Exemplo n.º 13
0
        public async Task Can_AddToList_and_GetAllFromList()
        {
            foreach (var x in storeMembers)
            {
                await RedisAsync.AddItemToListAsync(ListId, x);
            }

            var members = await RedisAsync.GetAllItemsFromListAsync(ListId);

            AssertAreEqual(members, storeMembers);
        }
Exemplo n.º 14
0
        public async Task Can_Set_and_Get_key_with_space()
        {
            await RedisAsync.SetValueAsync("key with space", Value);

            var valueBytes = await NativeAsync.GetAsync("key with space");

            var valueString = GetString(valueBytes);
            await RedisAsync.RemoveAsync("key with space");

            Assert.That(valueString, Is.EqualTo(Value));
        }
Exemplo n.º 15
0
        public async Task Can_GetValues_JSON_strings()
        {
            var val = "{\"AuthorId\":0,\"Created\":\"\\/Date(1345961754013)\\/\",\"Name\":\"test\",\"Base64\":\"BQELAAEBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAViA/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP8BWAFYgP8BWAFYAViA/wFYAVgBWID/AVgBWAFYgP8BWAFYAViA/4D/gP+A/4D/AVgBWID/gP8BWID/gP8BWID/gP+A/wFYgP+A/4D/gP8BWID/gP+A/4D/gP+A/wFYAViA/4D/AViA/4D/AVgBWAFYgP8BWAFYAViA/4D/AViA/4D/gP+A/4D/gP8BWAFYgP+A/wFYgP+A/wFYgP+A/4D/gP+A/wFYgP+A/wFYgP+A/4D/gP+A/4D/AVgBWID/gP8BWID/gP8BWAFYAViA/wFYAVgBWID/gP8BWID/gP+A/4D/gP+A/wFYAViA/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP8BWAFYgP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/AVgBWID/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/wFYAViA/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP8BWAFYgP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/AVgBWID/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/4D/gP+A/wFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAFYAVgBWAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"}";

            await RedisAsync.SetValueAsync("UserLevel/1", val);

            var vals = await RedisAsync.GetValuesAsync(new List <string>(new[] { "UserLevel/1" }));

            Assert.That(vals.Count, Is.EqualTo(1));
            Assert.That(vals[0], Is.EqualTo(val));
        }
        public async Task Can_Store()
        {
            foreach (var x in testModels)
            {
                await RedisAsync.StoreAsync(x);
            }

            var allModels = (await RedisAsync.As <TestModel>().GetAllAsync()).OrderBy(x => x.Age).ToList();

            Assert.That(allModels, Is.EquivalentTo(testModels));
        }
Exemplo n.º 17
0
        public async Task Can_Expire_Ms()
        {
            await RedisAsync.SetValueAsync("key", "val");

            await RedisAsync.ExpireEntryInAsync("key", TimeSpan.FromMilliseconds(100));

            Assert.That(await RedisAsync.ContainsKeyAsync("key"), Is.True);
            await Task.Delay(500);

            Assert.That(await RedisAsync.ContainsKeyAsync("key"), Is.False);
        }
Exemplo n.º 18
0
        public async Task Can_RemoveEndFromList()
        {
            foreach (var x in storeMembers)
            {
                await RedisAsync.AddItemToListAsync(ListId, x);
            }

            var item1 = await RedisAsync.RemoveEndFromListAsync(ListId);

            Assert.That(item1, Is.EqualTo(storeMembers.Last()));
        }
Exemplo n.º 19
0
        public async Task Can_BlockingRemoveStartFromList()
        {
            foreach (var x in storeMembers)
            {
                await RedisAsync.AddItemToListAsync(ListId, x);
            }

            var item1 = await RedisAsync.BlockingRemoveStartFromListAsync(ListId, null);

            Assert.That(item1, Is.EqualTo(storeMembers.First()));
        }
Exemplo n.º 20
0
        public async Task Can_GetItemFromList()
        {
            foreach (var x in storeMembers)
            {
                await RedisAsync.AddItemToListAsync(ListId, x);
            }

            var storeMember3 = storeMembers[2];
            var item3        = await RedisAsync.GetItemFromListAsync(ListId, 2);

            Assert.That(item3, Is.EqualTo(storeMember3));
        }
Exemplo n.º 21
0
        public async Task GetKeys_returns_matching_collection()
        {
            await RedisAsync.SetAsync("ss-tests:a1", "One");

            await RedisAsync.SetAsync("ss-tests:a2", "One");

            await RedisAsync.SetAsync("ss-tests:b3", "One");

            var matchingKeys = await RedisAsync.SearchKeysAsync("ss-tests:a*");

            Assert.That(matchingKeys.Count, Is.EqualTo(2));
        }
Exemplo n.º 22
0
        public async Task Can_store_multiple_keys()
        {
            var keys = 5.Times(x => "key" + x);
            var vals = 5.Times(x => "val" + x);

            using var redis = RedisClient.New();
            await RedisAsync.SetAllAsync(keys, vals);

            var all = await RedisAsync.GetValuesAsync(keys);

            Assert.AreEqual(vals, all);
        }
Exemplo n.º 23
0
        public async Task Can_save_via_string()
        {
            var dtos = 10.Times(i => new Dummy {
                Id = i, Name = "Name" + i
            });

            await RedisAsync.SetValueAsync("dummy:strings", dtos.ToJson());

            var fromDtos = (await RedisAsync.GetValueAsync("dummy:strings")).FromJson <List <Dummy> >();

            Assert.That(fromDtos.Count, Is.EqualTo(10));
        }
Exemplo n.º 24
0
        public async Task Can_scan_and_search_10_collection()
        {
            await RedisAsync.FlushAllAsync();

            var keys = 11.Times(x => "KEY" + x);
            await RedisAsync.SetAllAsync(keys.ToSafeDictionary(x => x));

            var ret = await NativeAsync.ScanAsync(0, 11, match : "KEY1*");

            Assert.That(ret.Cursor, Is.GreaterThanOrEqualTo(0));
            Assert.That(ret.AsStrings(), Is.EquivalentTo(new[] { "KEY1", "KEY10" }));
        }
Exemplo n.º 25
0
        public async Task Can_scan_10_collection()
        {
            await RedisAsync.FlushAllAsync();

            var keys = 10.Times(x => "KEY" + x);
            await RedisAsync.SetAllAsync(keys.ToSafeDictionary(x => x));

            var ret = await NativeAsync.ScanAsync(0);

            Assert.That(ret.Cursor, Is.GreaterThanOrEqualTo(0));
            Assert.That(ret.AsStrings(), Is.EquivalentTo(keys));
        }
Exemplo n.º 26
0
        public async Task Can_save_via_types()
        {
            var dtos = 10.Times(i => new Dummy {
                Id = i, Name = "Name" + i
            });

            await RedisAsync.SetAsync("dummy:strings", dtos);

            var fromDtos = await RedisAsync.GetAsync <List <Dummy> >("dummy:strings");

            Assert.That(fromDtos.Count, Is.EqualTo(10));
        }
Exemplo n.º 27
0
        public async Task Can_Set_and_Get_key_with_spaces()
        {
            const string key = "key with spaces";

            await RedisAsync.SetValueAsync(key, Value);

            var valueBytes = await NativeAsync.GetAsync(key);

            var valueString = GetString(valueBytes);

            Assert.That(valueString, Is.EqualTo(Value));
        }
Exemplo n.º 28
0
        public async Task Can_StoreObject()
        {
            object poco = new MyPoco {
                Id = 1, Name = "Test"
            };

            await RedisAsync.StoreObjectAsync(poco);

            Assert.That(await RedisAsync.GetValueAsync(RedisRaw.NamespacePrefix + "urn:mypoco:1"), Is.EqualTo("{\"Id\":1,\"Name\":\"Test\"}"));

            Assert.That(await RedisAsync.PopItemFromSetAsync(RedisRaw.NamespacePrefix + "ids:MyPoco"), Is.EqualTo("1"));
        }
Exemplo n.º 29
0
        public async Task Can_SScan_10_sets()
        {
            await RedisAsync.FlushAllAsync();

            var items = 10.Times(x => "item" + x);
            await items.ForEachAsync(async x => await RedisAsync.AddItemToSetAsync("scanset", x));

            var ret = await NativeAsync.SScanAsync("scanset", 0);

            Assert.That(ret.Cursor, Is.GreaterThanOrEqualTo(0));
            Assert.That(ret.AsStrings(), Is.EquivalentTo(items));
        }
        public async Task Can_GetRangeFromSortedSetByHighestScore_from_sorted_set()
        {
            await storeMembers.ForEachAsync(async x => await RedisAsync.AddItemToSortedSetAsync(SetId, x));

            storeMembers.Sort((x, y) => y.CompareTo(x));
            var memberRage = storeMembers.Where(x =>
                                                x.CompareTo("four") >= 0 && x.CompareTo("three") <= 0).ToList();

            var range = await RedisAsync.GetRangeFromSortedSetByHighestScoreAsync(SetId, "four", "three");

            Assert.That(range.EquivalentTo(memberRage));
        }