/// <summary> /// Use StringSetAsync to create a new entry into Redis with the PrimaryKey as the key /// </summary> /// <param name="supportTicket"></param> /// <returns></returns> public async Task <Boolean> AddNew(RedisItem redisItem) { try { IDatabase cache = RedisConnection.GetDatabase(); await cache.StringSetAsync(redisItem.PrimaryKey, JsonConvert.SerializeObject(redisItem.redisJSON)); return(true); } catch (Exception ex) { Debug.WriteLine($"DataHelper.AddNew({redisItem.PrimaryKey}): {ex.Message} - {ex.StackTrace}"); return(false); } }
/// <summary> /// Retrieves all keys in the Redis Server, and adds the complete Deserialized redisItem object into the passed in ObservableCollection /// </summary> /// <param name="ticketList"></param> /// <returns></returns> public async Task <ObservableCollection <RedisItem> > GetItems(ObservableCollection <RedisItem> ticketList) { try { IDatabase cache = RedisConnection.GetDatabase(); IDatabase db = RedisConnection.GetDatabase(); var endPoint = RedisConnection.GetEndPoints().First(); RedisKey[] keys = RedisConnection.GetServer(endPoint).Keys(pattern: "*").ToArray(); foreach (var key in keys) { try { var CacheValue = await cache.StringGetAsync(key); if (!string.IsNullOrEmpty(CacheValue)) { Debug.WriteLine($"Retrieved from Redis: {JsonConvert.DeserializeObject(CacheValue)}"); RedisItem tempObject = new RedisItem() { PrimaryKey = key, redisJSON = JsonConvert.DeserializeObject <Dictionary <string, string> >(CacheValue) }; ticketList.Add(tempObject); } } catch (Exception ex) { Debug.WriteLine($"Exception retriving individual Cache Value: " + ex.Message); } } return(ticketList); } catch (Exception ex) { Debug.WriteLine($"Get all redis entries exception: " + ex.Message); throw new RedisConnectionException(ConnectionFailureType.UnableToConnect, "Unable to connect to retrieve all support tickets"); } }