private static byte[] ToByteArray(Hipstershop.Cart cart) { if (cart == null) { return(null); } return(cart.ToByteArray()); }
public async Task EmptyCartAsync(string userId) { Console.WriteLine($"EmptyCartAsync called with userId={userId}"); try { var cart = new Hipstershop.Cart(); await _cache.SetAsync(userId, cart.ToByteArray()); } catch (Exception ex) { throw new RpcException(new Status(StatusCode.FailedPrecondition, $"Can't access cart storage. {ex}")); } }
public RedisCartStore(string redisAddress) { // Serialize empty cart into byte array. var cart = new Hipstershop.Cart(); emptyCartBytes = cart.ToByteArray(); connectionString = $"{redisAddress},ssl=false,allowAdmin=true,connectRetry=5"; redisConnectionOptions = ConfigurationOptions.Parse(connectionString); // Try to reconnect if first retry failed (up to 5 times with exponential backoff) redisConnectionOptions.ConnectRetry = REDIS_RETRY_NUM; redisConnectionOptions.ReconnectRetryPolicy = new ExponentialRetry(100); redisConnectionOptions.KeepAlive = 180; }