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