2021-11-11 15:56:02 +08:00
|
|
|
package router
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
|
|
|
import (
|
2022-09-09 18:26:08 +08:00
|
|
|
"mayfly-go/internal/redis/api"
|
|
|
|
|
"mayfly-go/internal/redis/application"
|
2022-10-26 20:49:29 +08:00
|
|
|
tagapp "mayfly-go/internal/tag/application"
|
2022-06-02 17:41:11 +08:00
|
|
|
"mayfly-go/pkg/ctx"
|
2021-07-28 18:03:19 +08:00
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func InitRedisRouter(router *gin.RouterGroup) {
|
|
|
|
|
redis := router.Group("redis")
|
|
|
|
|
{
|
2021-09-11 14:04:09 +08:00
|
|
|
rs := &api.Redis{
|
2022-10-26 20:49:29 +08:00
|
|
|
RedisApp: application.GetRedisApp(),
|
|
|
|
|
TagApp: tagapp.GetTagTreeApp(),
|
2021-07-28 18:03:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取redis list
|
|
|
|
|
redis.GET("", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.RedisList)
|
|
|
|
|
})
|
|
|
|
|
|
2022-11-18 17:52:30 +08:00
|
|
|
save := ctx.NewLogInfo("redis-保存信息").WithSave(true)
|
2021-07-28 18:03:19 +08:00
|
|
|
redis.POST("", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(save).Handle(rs.Save)
|
|
|
|
|
})
|
|
|
|
|
|
2022-08-02 21:44:01 +08:00
|
|
|
redis.GET(":id/pwd", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.GetRedisPwd)
|
|
|
|
|
})
|
|
|
|
|
|
2022-11-18 17:52:30 +08:00
|
|
|
delRedis := ctx.NewLogInfo("redis-删除信息").WithSave(true)
|
2021-07-28 18:03:19 +08:00
|
|
|
redis.DELETE(":id", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(delRedis).Handle(rs.DeleteRedis)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redis.GET(":id/info", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.RedisInfo)
|
|
|
|
|
})
|
|
|
|
|
|
2022-07-10 12:14:06 +08:00
|
|
|
redis.GET(":id/cluster-info", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.ClusterInfo)
|
|
|
|
|
})
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
// 获取指定redis keys
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/scan", func(c *gin.Context) {
|
2021-07-28 18:03:19 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.Scan)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 删除key
|
2022-11-14 18:07:27 +08:00
|
|
|
deleteKeyL := ctx.NewLogInfo("redis-删除key").WithSave(true)
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.DELETE(":id/:db/key", func(c *gin.Context) {
|
2021-07-28 18:03:19 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(deleteKeyL).Handle(rs.DeleteKey)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 获取string类型值
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.GET(":id/:db/string-value", func(c *gin.Context) {
|
2021-07-28 18:03:19 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.GetStringValue)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 设置string类型值
|
2022-11-14 18:07:27 +08:00
|
|
|
setStringL := ctx.NewLogInfo("redis-setString").WithSave(true)
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/string-value", func(c *gin.Context) {
|
2022-11-14 18:07:27 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(setStringL).Handle(rs.SetStringValue)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
2022-08-05 21:41:21 +08:00
|
|
|
// hscan
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.GET(":id/:db/hscan", func(c *gin.Context) {
|
2022-08-05 21:41:21 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.Hscan)
|
|
|
|
|
})
|
|
|
|
|
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.GET(":id/:db/hget", func(c *gin.Context) {
|
2022-08-05 21:41:21 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.Hget)
|
|
|
|
|
})
|
|
|
|
|
|
2022-11-14 18:07:27 +08:00
|
|
|
hdelL := ctx.NewLogInfo("redis-hdel").WithSave(true)
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.DELETE(":id/:db/hdel", func(c *gin.Context) {
|
2022-11-14 18:07:27 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(hdelL).Handle(rs.Hdel)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
2022-01-12 16:00:31 +08:00
|
|
|
// 设置hash类型值
|
2022-11-14 18:07:27 +08:00
|
|
|
setHashValueL := ctx.NewLogInfo("redis-setHashValue").WithSave(true)
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/hash-value", func(c *gin.Context) {
|
2022-11-14 18:07:27 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(setHashValueL).Handle(rs.SetHashValue)
|
2022-01-12 16:00:31 +08:00
|
|
|
})
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
// 获取set类型值
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.GET(":id/:db/set-value", func(c *gin.Context) {
|
2021-07-28 18:03:19 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.GetSetValue)
|
|
|
|
|
})
|
|
|
|
|
|
2022-01-12 16:00:31 +08:00
|
|
|
// 设置set类型值
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/set-value", func(c *gin.Context) {
|
2022-01-12 16:00:31 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.SetSetValue)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
2022-09-22 11:56:21 +08:00
|
|
|
|
|
|
|
|
// 获取list类型值
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.GET(":id/:db/list-value", func(c *gin.Context) {
|
2022-09-22 11:56:21 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.GetListValue)
|
|
|
|
|
})
|
|
|
|
|
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/list-value", func(c *gin.Context) {
|
2022-09-22 11:56:21 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.SaveListValue)
|
|
|
|
|
})
|
|
|
|
|
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/list-value/lset", func(c *gin.Context) {
|
2022-09-22 11:56:21 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).Handle(rs.SetListValue)
|
|
|
|
|
})
|
2021-07-28 18:03:19 +08:00
|
|
|
}
|
|
|
|
|
}
|