2024-09-02 09:00:50 +08:00
|
|
|
|
using Bunny.Dao.Model.Result;
|
2024-08-09 10:06:17 +08:00
|
|
|
|
using Bunny.Service.IService;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace Bunny.WebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 操作Redis相关内容
|
|
|
|
|
/// </summary>
|
2024-08-09 22:31:06 +08:00
|
|
|
|
[Route("/api/[controller]/[action]")]
|
2024-08-09 10:06:17 +08:00
|
|
|
|
public class RedisOptionController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IRedisOptionService _redisOptionService;
|
|
|
|
|
|
|
|
|
|
public RedisOptionController(IRedisOptionService redisOptionService)
|
|
|
|
|
{
|
|
|
|
|
_redisOptionService = redisOptionService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
{
|
|
|
|
|
_redisOptionService.AddStringValue(key, value);
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
var queryStringKey = _redisOptionService.QueryStringKey(key);
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
_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>
|
2024-08-10 04:18:03 +08:00
|
|
|
|
[HttpGet]
|
2024-08-09 22:31:06 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
2024-08-09 10:06:17 +08:00
|
|
|
|
}
|