OwnRedis.Client
1.1.0
dotnet add package OwnRedis.Client --version 1.1.0
NuGet\Install-Package OwnRedis.Client -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OwnRedis.Client" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OwnRedis.Client" Version="1.1.0" />
<PackageReference Include="OwnRedis.Client" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OwnRedis.Client --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OwnRedis.Client, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OwnRedis.Client@1.1.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OwnRedis.Client&version=1.1.0
#tool nuget:?package=OwnRedis.Client&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Клиентская библиотека для работы с распределённым кешем OwnRedis. Предоставляет простой API для кеширования данных в .NET-приложениях.
Установка
dotnet add package OwnRedis.Client
OwnRedis.Client
Клиентская библиотека для работы с распределённым кешем OwnRedis. Предоставляет простой API для кеширования данных в .NET-приложениях.
Установка
dotnet add package OwnRedis.Client
Требования
- .NET 8.0+
- Запущенный сервер OwnRedis (см. инструкцию по запуску)
Быстрый старт
1. Регистрация в DI
builder.Services.AddOwnRedisClient(options =>
{
options.BaseUrl = "https://your-server.com";
options.DefaultTtl = TimeSpan.FromMinutes(10);
});
2. Использование
public class ProductService
{
private readonly IOwnRedisClient _cache;
public ProductService(IOwnRedisClient cache)
{
_cache = cache;
}
public async Task<Product?> GetProduct(int id)
{
// Ищем в кеше
var cached = await _cache.GetAsync<Product>($"product:{id}");
if (cached != null)
return cached;
// Нет в кеше — идём в БД
var product = await _db.Products.FindAsync(id);
// Сохраняем в кеш на 5 минут
if (product != null)
await _cache.SetAsync($"product:{id}", product, TimeSpan.FromMinutes(5));
return product;
}
}
API
| Метод | Описание |
|---|---|
GetAsync<T>(key) |
Получить значение по ключу |
SetAsync<T>(key, value, ttl?) |
Сохранить значение (TTL опционально) |
DeleteAsync(key) |
Удалить ключ |
ExistsAsync(key) |
Проверить существование ключа |
Настройки
| Параметр | Описание | По умолчанию |
|---|---|---|
BaseUrl |
URL сервера OwnRedis | Обязательный |
DefaultTtl |
TTL по умолчанию, если не указан явно | 10 минут |
Обработка ошибок
try
{
var data = await _cache.GetAsync<Product>("key");
}
catch (HttpRequestException)
{
// Сервер недоступен — работаем без кеша
}
Сервер
Исходный код и инструкция по запуску сервера: OwnRedis.Backend
Лицензия
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.Http (>= 10.0.7)
- OwnRedis.Core (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.