public void RemoveProductInfo(string productName) { string key = PrefixConstants.GetProductInfoKey(productName); byte[] bytesKey = Encoding.UTF8.GetBytes(key); try { _database.Delete(bytesKey); } catch (Exception e) { _logger.Error(e, $"Failed to remove info for product {productName}"); } }
public void PutProductInfo(ProductEntity product) { string key = PrefixConstants.GetProductInfoKey(product.Name); byte[] bytesKey = Encoding.UTF8.GetBytes(key); string stringData = JsonSerializer.Serialize(product); byte[] bytesValue = Encoding.UTF8.GetBytes(stringData); try { _database.Put(bytesKey, bytesValue); } catch (Exception e) { _logger.Error(e, $"Failed to put product info for {product.Name}"); } }
public ProductEntity GetProductInfo(string productName) { string key = PrefixConstants.GetProductInfoKey(productName); byte[] bytesKey = Encoding.UTF8.GetBytes(key); try { bool isRead = _database.TryRead(bytesKey, out byte[] value); if (!isRead) { throw new ServerDatabaseException("Failed to read product info"); } return(JsonSerializer.Deserialize <ProductEntity>(Encoding.UTF8.GetString(value))); } catch (Exception e) { _logger.Error(e, $"Failed to read info for product {productName}"); } return(null); }