Merge conflict fix for redis cache exception handling
This commit is contained in:
parent
84ff69147e
commit
17ffcb9a6e
2 changed files with 10 additions and 5 deletions
|
@ -17,22 +17,26 @@ namespace cartservice.cartstore
|
||||||
|
|
||||||
private readonly byte[] emptyCartBytes;
|
private readonly byte[] emptyCartBytes;
|
||||||
private readonly string connectionString;
|
private readonly string connectionString;
|
||||||
|
private readonly string redisAddr;
|
||||||
|
|
||||||
public RedisCartStore(string redisAddress)
|
public RedisCartStore(string redisAddress)
|
||||||
{
|
{
|
||||||
// Serialize empty cart into byte array.
|
// Serialize empty cart into byte array.
|
||||||
var cart = new Hipstershop.Cart();
|
var cart = new Hipstershop.Cart();
|
||||||
emptyCartBytes = cart.ToByteArray();
|
emptyCartBytes = cart.ToByteArray();
|
||||||
|
this.redisAddr = redisAddress;
|
||||||
connectionString = $"{redisAddress},ssl=false,allowAdmin=true";
|
connectionString = $"{redisAddress},ssl=false,allowAdmin=true,connectRetry=5";
|
||||||
Console.WriteLine($"Going to use Redis cache at this address: {connectionString}");
|
Console.WriteLine($"Going to use Redis cache at this address: {connectionString}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task InitializeAsync()
|
public Task InitializeAsync()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Connecting to Redis: " + connectionString);
|
Console.WriteLine("Connecting to Redis: " + connectionString);
|
||||||
redis = await ConnectionMultiplexer.ConnectAsync(connectionString, Console.Out);
|
|
||||||
|
redis = ConnectionMultiplexer.Connect(connectionString);
|
||||||
Console.WriteLine("Connected successfully to Redis");
|
Console.WriteLine("Connected successfully to Redis");
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddItemAsync(string userId, string productId, int quantity)
|
public async Task AddItemAsync(string userId, string productId, int quantity)
|
||||||
|
@ -84,8 +88,8 @@ namespace cartservice.cartstore
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var db = redis.GetDatabase();
|
var db = redis.GetDatabase();
|
||||||
|
|
||||||
// Access the cart from the cache
|
// Access the cart from the cache
|
||||||
|
|
||||||
var value = await db.HashGetAsync(userId, CART_FIELD_NAME);
|
var value = await db.HashGetAsync(userId, CART_FIELD_NAME);
|
||||||
|
|
||||||
if (!value.IsNull)
|
if (!value.IsNull)
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace cartservice
|
||||||
};
|
};
|
||||||
var cart = await client.GetCartAsync(request);
|
var cart = await client.GetCartAsync(request);
|
||||||
Assert.NotNull(cart);
|
Assert.NotNull(cart);
|
||||||
|
|
||||||
// All grpc objects implement IEquitable, so we can compare equality with by-value semantics
|
// All grpc objects implement IEquitable, so we can compare equality with by-value semantics
|
||||||
Assert.Equal(new Cart(), cart);
|
Assert.Equal(new Cart(), cart);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue