2024-09-02 21:28:21 +08:00
|
|
|
|
using Bunny.Dao.Common.Result;
|
2024-08-09 10:06:17 +08:00
|
|
|
|
using Bunny.Service.IService;
|
2024-09-02 09:31:34 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2024-08-09 10:06:17 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace Bunny.WebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 操作Redis相关内容
|
|
|
|
|
/// </summary>
|
2024-09-02 09:31:34 +08:00
|
|
|
|
[Microsoft.AspNetCore.Mvc.Route("/api/[controller]/[action]")]
|
2024-08-09 10:06:17 +08:00
|
|
|
|
public class RedisOptionController : ControllerBase
|
|
|
|
|
{
|
2024-09-02 09:31:34 +08:00
|
|
|
|
[Inject] public required IRedisOptionService RedisOptionService { get; set; }
|
2024-08-09 10:06:17 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加Redis中一个值
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-08-10 04:18:03 +08:00
|
|
|
|
[HttpPost]
|
2024-08-09 10:06:17 +08:00
|
|
|
|
public Result<string> AddStringValue(string key, string value)
|
|
|
|
|
{
|
2024-09-02 09:31:34 +08:00
|
|
|
|
RedisOptionService.AddStringValue(key, value);
|
2024-08-09 10:06:17 +08:00
|
|
|
|
return Result<string>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询字符串Key
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-08-10 04:18:03 +08:00
|
|
|
|
[HttpPost]
|
2024-08-09 10:06:17 +08:00
|
|
|
|
public Result<string> QueryStringKey(string key)
|
|
|
|
|
{
|
2024-09-02 09:31:34 +08:00
|
|
|
|
var queryStringKey = RedisOptionService.QueryStringKey(key);
|
2024-08-09 10:06:17 +08:00
|
|
|
|
return Result<string>.Success(queryStringKey);
|
|
|
|
|
}
|
2024-08-09 22:31:06 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加时间限制的key
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-08-10 04:18:03 +08:00
|
|
|
|
[HttpPost]
|
2024-08-09 22:31:06 +08:00
|
|
|
|
public Result<string> AddTimeRedisKey(string key, string value)
|
|
|
|
|
{
|
2024-09-02 09:31:34 +08:00
|
|
|
|
RedisOptionService.AddTimeRedisKey(key, value);
|
2024-08-09 22:31:06 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2024-09-02 09:31:34 +08:00
|
|
|
|
RedisOptionService.AddTimeRedisKeyTtl(key, value);
|
2024-08-09 22:31:06 +08:00
|
|
|
|
return Result<string>.Success(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Redis存入JSON内容
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-08-10 04:18:03 +08:00
|
|
|
|
[HttpGet]
|
2024-08-09 22:31:06 +08:00
|
|
|
|
public Result<string> AddJson()
|
|
|
|
|
{
|
2024-09-02 09:31:34 +08:00
|
|
|
|
var json = RedisOptionService.AddJson();
|
2024-08-09 22:31:06 +08:00
|
|
|
|
return Result<string>.Success(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除Redis中key
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpDelete]
|
|
|
|
|
public Result<string> DeleteKey(string key)
|
|
|
|
|
{
|
2024-09-02 09:31:34 +08:00
|
|
|
|
RedisOptionService.DeleteKey(key);
|
2024-08-09 22:31:06 +08:00
|
|
|
|
return Result<string>.Success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Redis中的事务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public Result<string> SetRedisCreateTransaction(string key, string value)
|
|
|
|
|
{
|
2024-09-02 09:31:34 +08:00
|
|
|
|
var redisCreateTransaction = RedisOptionService.SetRedisCreateTransaction(key, value);
|
2024-08-09 22:31:06 +08:00
|
|
|
|
return Result<string>.Success(redisCreateTransaction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Redis设置Hash值,
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public Result<string> AddHashWithRedis(string key, double keyExpire = 6.0)
|
|
|
|
|
{
|
2024-09-02 09:31:34 +08:00
|
|
|
|
RedisOptionService.AddHashWithRedis(key, keyExpire);
|
2024-08-09 22:31:06 +08:00
|
|
|
|
return Result<string>.Success();
|
|
|
|
|
}
|
2024-08-09 10:06:17 +08:00
|
|
|
|
}
|