'Get data in redis with part of a key in .net core
I have these keys in my redis server with their data :
AdminIpoChangeEntity:0
AdminIpoChangeEntity:1
AdminIpoChangeEntity:2
AdminIpoChangeEntity:3
I want to pass just AdminIpoChangeEntity to my method and my method should return four records .
Here is my redis repository :
private IDatabase RedisDb => _connection.Value.GetDatabase();
//
private string Key(TEntity entity) => $"{typeof(TEntity).Name}:{entity.Id}";
private string Key(string id) => $"{typeof(TEntity).Name}:{id}";
public async Task<OperationResult> AddOrUpdateAsync(TEntity entity)
{
var val = System.Text.Json.JsonSerializer.Serialize(entity);
var res = await RedisDb.StringSetAsync(Key(entity), val);
return OperationResult<TEntity>.Succeed();
}
public async Task<OperationResult<TEntity>> GetByIdAsync(string id)
{
var value = await RedisDb.StringGetAsync(Key(id));
if (value.HasValue)
{
var result = System.Text.Json.JsonSerializer.Deserialize<TEntity>(value.ToString());
return OperationResult<TEntity>.Succeed(result);
}
return OperationResult<TEntity>.Succeed(null);
}
And I need this one :
public async Task<OperationResult<IList<TEntity>>> GetAllAsync()
{
var value = await RedisDb.StringGetAsync(Key(nameof(TEntity)));
throw new NotImplementedException();
}
My entity name is AdminIpoChangeEntity
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
