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"
|
2023-01-14 16:29:52 +08:00
|
|
|
"mayfly-go/pkg/req"
|
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) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.RedisList)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
2023-01-14 16:29:52 +08:00
|
|
|
save := req.NewLogInfo("redis-保存信息").WithSave(true)
|
2021-07-28 18:03:19 +08:00
|
|
|
redis.POST("", func(c *gin.Context) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).WithLog(save).Handle(rs.Save)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
2022-08-02 21:44:01 +08:00
|
|
|
redis.GET(":id/pwd", func(c *gin.Context) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.GetRedisPwd)
|
2022-08-02 21:44:01 +08:00
|
|
|
})
|
|
|
|
|
|
2023-01-14 16:29:52 +08:00
|
|
|
delRedis := req.NewLogInfo("redis-删除信息").WithSave(true)
|
2021-07-28 18:03:19 +08:00
|
|
|
redis.DELETE(":id", func(c *gin.Context) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).WithLog(delRedis).Handle(rs.DeleteRedis)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redis.GET(":id/info", func(c *gin.Context) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.RedisInfo)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
2022-07-10 12:14:06 +08:00
|
|
|
redis.GET(":id/cluster-info", func(c *gin.Context) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.ClusterInfo)
|
2022-07-10 12:14:06 +08:00
|
|
|
})
|
|
|
|
|
|
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) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.Scan)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
2023-04-16 00:50:36 +08:00
|
|
|
redis.GET(":id/:db/key-ttl", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).Handle(rs.TtlKey)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 保存数据权限
|
|
|
|
|
saveDataP := req.NewPermission("redis:data:save")
|
|
|
|
|
// 删除数据权限
|
|
|
|
|
deleteDataP := req.NewPermission("redis:data:del")
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
// 删除key
|
2023-01-14 16:29:52 +08:00
|
|
|
deleteKeyL := req.NewLogInfo("redis-删除key").WithSave(true)
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.DELETE(":id/:db/key", func(c *gin.Context) {
|
2023-04-16 00:50:36 +08:00
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithLog(deleteKeyL).
|
|
|
|
|
WithRequiredPermission(deleteDataP).
|
|
|
|
|
Handle(rs.DeleteKey)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
2023-04-16 00:50:36 +08:00
|
|
|
renameKeyL := req.NewLogInfo("redis-重命名key").WithSave(true)
|
|
|
|
|
redis.POST(":id/:db/rename-key", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithLog(renameKeyL).
|
|
|
|
|
WithRequiredPermission(saveDataP).
|
|
|
|
|
Handle(rs.RenameKey)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expireKeyL := req.NewLogInfo("redis-设置key过期时间").WithSave(true)
|
|
|
|
|
redis.POST(":id/:db/expire-key", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithLog(expireKeyL).
|
|
|
|
|
WithRequiredPermission(saveDataP).
|
|
|
|
|
Handle(rs.ExpireKey)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
persistKeyL := req.NewLogInfo("redis-移除key过期时间").WithSave(true)
|
|
|
|
|
redis.DELETE(":id/:db/persist-key", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithLog(persistKeyL).
|
|
|
|
|
WithRequiredPermission(saveDataP).
|
|
|
|
|
Handle(rs.PersistKey)
|
|
|
|
|
})
|
2023-03-15 11:41:03 +08:00
|
|
|
|
2023-06-15 19:18:29 +08:00
|
|
|
flushDbL := req.NewLogInfo("redis-flushdb").WithSave(true)
|
|
|
|
|
redis.DELETE(":id/:db/flushdb", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithLog(flushDbL).
|
|
|
|
|
WithRequiredPermission(saveDataP).
|
|
|
|
|
Handle(rs.FlushDb)
|
|
|
|
|
})
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
// 获取string类型值
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.GET(":id/:db/string-value", func(c *gin.Context) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.GetStringValue)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 设置string类型值
|
2023-01-14 16:29:52 +08:00
|
|
|
setStringL := req.NewLogInfo("redis-setString").WithSave(true)
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/string-value", func(c *gin.Context) {
|
2023-04-16 00:50:36 +08:00
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithLog(setStringL).
|
|
|
|
|
WithRequiredPermission(saveDataP).
|
|
|
|
|
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) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.Hscan)
|
2022-08-05 21:41:21 +08:00
|
|
|
})
|
|
|
|
|
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.GET(":id/:db/hget", func(c *gin.Context) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.Hget)
|
2022-08-05 21:41:21 +08:00
|
|
|
})
|
|
|
|
|
|
2023-04-16 00:50:36 +08:00
|
|
|
hsetL := req.NewLogInfo("redis-hset").WithSave(true)
|
|
|
|
|
redis.POST(":id/:db/hset", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithLog(hsetL).
|
|
|
|
|
WithRequiredPermission(saveDataP).
|
|
|
|
|
Handle(rs.Hset)
|
|
|
|
|
})
|
|
|
|
|
|
2023-01-14 16:29:52 +08:00
|
|
|
hdelL := req.NewLogInfo("redis-hdel").WithSave(true)
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.DELETE(":id/:db/hdel", func(c *gin.Context) {
|
2023-04-16 00:50:36 +08:00
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithLog(hdelL).
|
|
|
|
|
WithRequiredPermission(deleteDataP).
|
|
|
|
|
Handle(rs.Hdel)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
2022-01-12 16:00:31 +08:00
|
|
|
// 设置hash类型值
|
2023-01-14 16:29:52 +08:00
|
|
|
setHashValueL := req.NewLogInfo("redis-setHashValue").WithSave(true)
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/hash-value", func(c *gin.Context) {
|
2023-04-16 00:50:36 +08:00
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithLog(setHashValueL).
|
|
|
|
|
WithRequiredPermission(saveDataP).
|
|
|
|
|
Handle(rs.SetHashValue)
|
2022-01-12 16:00:31 +08:00
|
|
|
})
|
|
|
|
|
|
2023-04-16 00:50:36 +08:00
|
|
|
// set操作
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.GET(":id/:db/set-value", func(c *gin.Context) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.GetSetValue)
|
2021-07-28 18:03:19 +08:00
|
|
|
})
|
|
|
|
|
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/set-value", func(c *gin.Context) {
|
2023-04-16 00:50:36 +08:00
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithRequiredPermission(saveDataP).
|
|
|
|
|
Handle(rs.SetSetValue)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redis.GET(":id/:db/scard", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).Handle(rs.Scard)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redis.POST(":id/:db/sscan", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).Handle(rs.Sscan)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redis.POST(":id/:db/sadd", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithRequiredPermission(saveDataP).
|
|
|
|
|
Handle(rs.Sadd)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redis.POST(":id/:db/srem", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithRequiredPermission(deleteDataP).
|
|
|
|
|
Handle(rs.Srem)
|
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) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.GetListValue)
|
2022-09-22 11:56:21 +08:00
|
|
|
})
|
|
|
|
|
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/list-value", func(c *gin.Context) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.SaveListValue)
|
2022-09-22 11:56:21 +08:00
|
|
|
})
|
|
|
|
|
|
2022-09-29 13:14:50 +08:00
|
|
|
redis.POST(":id/:db/list-value/lset", func(c *gin.Context) {
|
2023-01-14 16:29:52 +08:00
|
|
|
req.NewCtxWithGin(c).Handle(rs.SetListValue)
|
2022-09-22 11:56:21 +08:00
|
|
|
})
|
2023-04-16 00:50:36 +08:00
|
|
|
|
|
|
|
|
redis.POST(":id/:db/lrem", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithRequiredPermission(deleteDataP).
|
|
|
|
|
Handle(rs.Lrem)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// zset操作
|
|
|
|
|
redis.GET(":id/:db/zcard", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).Handle(rs.ZCard)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redis.GET(":id/:db/zscan", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).Handle(rs.ZScan)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redis.GET(":id/:db/zrevrange", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).Handle(rs.ZRevRange)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redis.POST(":id/:db/zrem", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithRequiredPermission(deleteDataP).
|
|
|
|
|
Handle(rs.ZRem)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
redis.POST(":id/:db/zadd", func(c *gin.Context) {
|
|
|
|
|
req.NewCtxWithGin(c).
|
|
|
|
|
WithRequiredPermission(saveDataP).
|
|
|
|
|
Handle(rs.ZAdd)
|
|
|
|
|
})
|
2021-07-28 18:03:19 +08:00
|
|
|
}
|
|
|
|
|
}
|