⚠ Deprecated: Legacy
Suggested alternative: Redis.Sharp
A better, smarter, and faster way to interact with Redis. While RediJson allows access to JSON models, direct hash calls remain the best way to maximize performance on Redis. Easily perform complex queries using LINQ and partially load/update your models.
$ dotnet add package AsyncRedisModelsA better; smarter and faster way to interact with Redis. While RediJson allows access to json models, direct hash calls remain the best way to maximize performance on Redis.
Easily perform complex queries using linq and partially load/update your models.
Initialize Redis Connection
Start by initializing the Redis connection with your Redis server details:
RedisSingleton.Initialize("your-redis-host", port, "your-password");
var character = await RedisRepository.CreateAsync<Character>();
character = await RedisRepository.LoadAsync<Character>(character.Id);
character.Username = "myUsername";
await character.PushAsync(s => s.Username);
await character.PullAsync(s => s.Username);
Console.WriteLine(character.Username); // Output the updated Username
var query = new RedisQuery<Character>();
var results = await query.Where(s => s.Username == "myUsername").SelectAsync();
public class Character : IAsyncModel
{
[Indexed(IndexType.Tag)]
public string Username { get; set; }
public string Id { get; set; }
public DateTime CreatedAt { get; set; }
public string IndexName()
{
return "character";
}
}
Indexed attribute can be used to index specific fields.
Implements IAsyncModel for Redis interaction.
await character.PushAsync(s => s.Username);
await character.PullAsync(s => s.Username);
await character.DeleteAsync();
await character.IncrementAsync(s => s.myNumber);
var characters = await RedisRepository.CreateManyAsync<Character>(100);
var characters = await RedisRepository.LoadManyAsync<Character>(new[] { "id1", "id2" });
Exceptions are thrown if Redis interactions fail (e.g., if an entity with the same ID already exists).
PushAsync : Save model properties to Redis.
PullAsync : Retrieve model properties from Redis.
IncrementAsync : Increment numeric properties atomically.
RedisSingleton handles the Redis connection and is used for all database operations.
Models must implement IAsyncModel for seamless integration with Redis.