chore: format with csharpier

This commit is contained in:
sam 2024-10-09 17:35:11 +02:00
parent 2f516dcb73
commit 4f54077c68
59 changed files with 2000 additions and 942 deletions

View file

@ -5,12 +5,12 @@ namespace Catalogger.Backend.Database.Redis;
public class RedisService(Config config)
{
private readonly ConnectionMultiplexer _multiplexer = ConnectionMultiplexer.Connect(config.Database.Redis!);
private readonly ConnectionMultiplexer _multiplexer = ConnectionMultiplexer.Connect(
config.Database.Redis!
);
private readonly JsonSerializerOptions _options = new()
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
};
private readonly JsonSerializerOptions _options =
new() { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower };
public IDatabase GetDatabase(int db = -1) => _multiplexer.GetDatabase(db);
@ -32,10 +32,18 @@ public class RedisService(Config config)
await GetDatabase().HashSetAsync(hashKey, fieldKey, json);
}
public async Task SetHashAsync<T>(string hashKey, IEnumerable<T> values, Func<T, string> keySelector)
public async Task SetHashAsync<T>(
string hashKey,
IEnumerable<T> values,
Func<T, string> keySelector
)
{
var hashEntries = values
.Select(v => new { Key = keySelector(v), Value = JsonSerializer.Serialize(v, _options) })
.Select(v => new
{
Key = keySelector(v),
Value = JsonSerializer.Serialize(v, _options),
})
.Select(v => new HashEntry(v.Key, v.Value));
await GetDatabase().HashSetAsync(hashKey, hashEntries.ToArray());
}
@ -45,4 +53,4 @@ public class RedisService(Config config)
var value = await GetDatabase().HashGetAsync(hashKey, fieldKey);
return value.IsNull ? default : JsonSerializer.Deserialize<T>(value!, _options);
}
}
}