I'm trying to remove an element from a Redis Sorted list without success
public bool Delete(int id)
{
try
{
var redisManager = new RedisManagerPool(Global.RedisConnector);
using (var redis = redisManager.GetClient())
{
var entities = redis.As<BookingRequestModel>();
var list = entities.SortedSets["BookingRequests"].GetAll();
//count = 320
var model = list.First(z=>z.Id == id);
list.Remove(model);
//count 319 - however when I refresh the page I still see my old data in grid ...
entities.Save();
return true;
}
}
catch (Exception ex)
{
return false;
}
}
also tried like this :
public bool Delete(int id)
{
try
{
var redisManager = new RedisManagerPool(Global.RedisConnector);
using (var redis = redisManager.GetClient())
{
var entities = redis.As<BookingRequestModel>();
var list = entities.SortedSets["BookingRequests"];
var model = list.First(z=>z.Id == id);
var result = entities.RemoveItemFromSortedSet(list, model); // result is false
entities.Save();
return true;
}
}
catch (Exception ex)
{
return false;
}
}
As I commented there I still can see the old data after removing them from grid.
Can you please help me with this ?
Don't understand why , but this is working :
public bool Delete(int id)
{
try
{
var redisManager = new RedisManagerPool(Global.RedisConnector);
using (var redis = redisManager.GetClient())
{
var items = redis.GetAllItemsFromSortedSet("BookingRequests");
foreach (var item in items)
{
var dto = item.FromJson<BookingRequestModel>();
if (dto.Id == id)
{
redis.RemoveItemFromSortedSet("BookingRequests", item);
break;
}
}
return true;
}
}
catch (Exception ex)
{
return false;
}
}