This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Web.Http;
|
||||
using StackExchange.Redis;
|
||||
using Auth.Services.DatabaseService;
|
||||
|
||||
namespace Auth.Controllers {
|
||||
[ApiController]
|
||||
[Route("api/db/")]
|
||||
public class RedisController : MistoxControllerBase {
|
||||
|
||||
private readonly ConnectionMultiplexer _redis;
|
||||
private readonly IDatabase _redisdb;
|
||||
|
||||
public RedisController(DatabaseService db) : base(db) {
|
||||
_redis = ConnectionMultiplexer.Connect("redis:6397");
|
||||
_redisdb = _redis.GetDatabase();
|
||||
}
|
||||
|
||||
[Route("get")]
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<string>> Get(string key) {
|
||||
RedisValue result = await _redisdb.StringGetAsync(key);
|
||||
return Ok(result.ToString());
|
||||
}
|
||||
|
||||
[Route("set")]
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> Set(string key, string value) {
|
||||
await _redisdb.StringSetAsync(key, value);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user