110 lines
3.0 KiB
C#
110 lines
3.0 KiB
C#
using Bunny.Dao.Common.Result;
|
||
using Bunny.Service.IService;
|
||
using Microsoft.AspNetCore.Components;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
|
||
namespace Bunny.WebApi.Controllers;
|
||
|
||
/// <summary>
|
||
/// 操作Redis相关内容
|
||
/// </summary>
|
||
[Microsoft.AspNetCore.Mvc.Route("/api/[controller]/[action]")]
|
||
public class RedisOptionController : ControllerBase
|
||
{
|
||
[Inject] public required IRedisOptionService RedisOptionService { get; set; }
|
||
|
||
/// <summary>
|
||
/// 添加Redis中一个值
|
||
/// </summary>
|
||
/// <param name="key"></param>
|
||
/// <param name="value"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public Result<string> AddStringValue(string key, string value)
|
||
{
|
||
RedisOptionService.AddStringValue(key, value);
|
||
return Result<string>.Success();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询字符串Key
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public Result<string> QueryStringKey(string key)
|
||
{
|
||
var queryStringKey = RedisOptionService.QueryStringKey(key);
|
||
return Result<string>.Success(queryStringKey);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加时间限制的key
|
||
/// </summary>
|
||
/// <param name="key"></param>
|
||
/// <param name="value"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public Result<string> AddTimeRedisKey(string key, string value)
|
||
{
|
||
RedisOptionService.AddTimeRedisKey(key, value);
|
||
return Result<string>.Success(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 当前存在时
|
||
/// </summary>
|
||
/// <param name="key"></param>
|
||
/// <param name="value"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public Result<string> AddTimeRedisKeyTtl(string key, string value)
|
||
{
|
||
RedisOptionService.AddTimeRedisKeyTtl(key, value);
|
||
return Result<string>.Success(value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Redis存入JSON内容
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public Result<string> AddJson()
|
||
{
|
||
var json = RedisOptionService.AddJson();
|
||
return Result<string>.Success(json);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除Redis中key
|
||
/// </summary>
|
||
/// <param name="key"></param>
|
||
/// <returns></returns>
|
||
[HttpDelete]
|
||
public Result<string> DeleteKey(string key)
|
||
{
|
||
RedisOptionService.DeleteKey(key);
|
||
return Result<string>.Success();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Redis中的事务
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public Result<string> SetRedisCreateTransaction(string key, string value)
|
||
{
|
||
var redisCreateTransaction = RedisOptionService.SetRedisCreateTransaction(key, value);
|
||
return Result<string>.Success(redisCreateTransaction);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Redis设置Hash值,
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public Result<string> AddHashWithRedis(string key, double keyExpire = 6.0)
|
||
{
|
||
RedisOptionService.AddHashWithRedis(key, keyExpire);
|
||
return Result<string>.Success();
|
||
}
|
||
} |