public void Test03Modify() { string key = "jsonTest03"; TestDO old = new TestDO { Key = key, value1 = 77, value2 = new byte[] { 0x01, 0x02, 0x03, 0x04 }, value3 = @"Hello redis@@!" }; //Try add to Redis this.cacheHelper.Add(key, old); Assert.True(this.cacheHelper.Exists(key)); TestDO result = this.cacheHelper.Get(key); logger.Debug($"Get orig key:value => {0}:{1}", key, result); //It's in Redis TestDO expected = new TestDO { Key = key, value1 = 66, value2 = new byte[] { 0x02, 0x03, 0x04 }, value3 = @"Hello redis@@!" }; this.cacheHelper.Add(key, expected); result = this.cacheHelper.Get(key); logger.Debug($"Get new key:value => {0}:{1}", key, result); //It's in Redis Assert.NotNull(result); Assert.Equal(expected, result); }
public void Test02RetriveJson() { string key = "jsonTest"; TestDO value = new TestDO { Key = key, value1 = 77, value2 = new byte[] { 0x01, 0x02, 0x03 }, value3 = "jsonTest with key 77" }; var db = this.redis.Connection.GetDatabase(); //Try and retrieve from Redis if (!db.KeyExists(key)) { if (db.StringSet(key, value.ToString())) //Add to Redis { logger.Debug($"Success set key:valule => {0}:{1}", key, value); } } RedisValue redisValue = db.StringGet(key); TestDO result = JsonConvert.DeserializeObject <TestDO>(redisValue.ToString()); logger.Debug($"Get key:value => {0}:{1}", key, result); //It's in Redis - return it }
public void Test04RemoveJson() { var db = this.redis.Connection.GetDatabase(); string key = "jsonTest"; if (db.KeyExists(key)) { TestDO orig = JsonConvert.DeserializeObject <TestDO>(db.StringGet(key).ToString()); logger.Debug($"Exists key:value => {0}:{1}", key, orig); // Remove it! Assert.True(db.KeyDelete(key)); } Assert.False(db.KeyExists(key)); }
public void Test01Add() { string key = "jsonTest01"; string value = "Hello Redis!"; TestDO expected = new TestDO { Key = key, value1 = 111, value2 = new byte[] { 0x01, 0x02, 0x03 }, value3 = value }; //Try add to Redis this.cacheHelper.Add(key, expected); Assert.True(this.cacheHelper.Exists(key)); TestDO result = this.cacheHelper.Get(key); logger.Debug($"Get add key:value => {0}:{1}", key, result); //It's in Redis Assert.NotNull(result); Assert.Equal(expected, result); }
public void Test04Delete() { string key = "jsonTest04"; TestDO old = new TestDO { Key = key, value1 = 77, value2 = new byte[] { 0x01, 0x02, 0x03, 0x04 }, value3 = @"Hello redis@@!" }; //Try add to Redis this.cacheHelper.Add(key, old); TestDO result = this.cacheHelper.Get(key); logger.Debug($"Exits key:value => {0}:{1}", key, result); //It's in Redis this.cacheHelper.Remove(key); result = this.cacheHelper.Get(key); logger.Debug($"After remove key:value => {0}:{1}", key, result); Assert.Null(this.cacheHelper.Get(key)); Assert.False(this.cacheHelper.Exists(key)); }
public void Test03ModifyJson() { string key = "jsonTest"; TestDO value = new TestDO { Key = key, value1 = 66, value2 = new byte[] { 0x02, 0x03, 0x04 }, value3 = "jsonTest with key 66" }; var db = this.redis.Connection.GetDatabase(); if (db.KeyExists(key)) { TestDO orig = JsonConvert.DeserializeObject <TestDO>(db.StringGet(key).ToString()); logger.Debug($"Exists key:value => {0}:{1}", key, orig); } // modify it db.StringSet(key, value.ToString(), null, When.Always); RedisValue redisValue = db.StringGet(key); TestDO result = JsonConvert.DeserializeObject <TestDO>(redisValue.ToString()); logger.Debug($"Get key:value => {0}:{1}", key, result); //It's in Redis - return it }