2024-07-21 11:00:08 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
"videoplayer/proto"
|
|
|
|
|
"videoplayer/worker"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func SetToolRedisList(key string, value string, expire int) (code int, message string) {
|
|
|
|
|
if expire == 0 {
|
|
|
|
|
if worker.PushRedisList(key, value) {
|
|
|
|
|
return proto.SuccessCode, "success"
|
|
|
|
|
} else {
|
|
|
|
|
return proto.OperationFailed, "push redis list failed"
|
|
|
|
|
}
|
|
|
|
|
} else if expire > 0 {
|
|
|
|
|
if worker.PushRedisListWithExpire(key, value, time.Duration(expire)) {
|
|
|
|
|
return proto.SuccessCode, "success"
|
|
|
|
|
} else {
|
|
|
|
|
return proto.OperationFailed, "push redis list with expire failed"
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return proto.ParameterError, "expire time can not be negative"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SetToolRedisSet(key string, value string, expire int) (code int, message string) {
|
|
|
|
|
if expire == 0 {
|
|
|
|
|
if worker.SetRedis(key, value) {
|
|
|
|
|
return proto.SuccessCode, "success"
|
|
|
|
|
} else {
|
|
|
|
|
return proto.OperationFailed, "set redis failed"
|
|
|
|
|
}
|
|
|
|
|
} else if expire > 0 {
|
|
|
|
|
if worker.SetRedisWithExpire(key, value, time.Duration(expire)) {
|
|
|
|
|
return proto.SuccessCode, "success"
|
|
|
|
|
} else {
|
|
|
|
|
return proto.OperationFailed, "set redis with expire failed"
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return proto.ParameterError, "expire time can not be negative"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SetToolRedisKV(key string, value string, expire int) (code int, message string) {
|
|
|
|
|
if expire == 0 {
|
|
|
|
|
if worker.SetRedis(key, value) {
|
|
|
|
|
return proto.SuccessCode, "success"
|
|
|
|
|
} else {
|
|
|
|
|
return proto.OperationFailed, "set redis failed"
|
|
|
|
|
}
|
|
|
|
|
} else if expire > 0 {
|
|
|
|
|
if worker.SetRedisWithExpire(key, value, time.Duration(expire)) {
|
|
|
|
|
return proto.SuccessCode, "success"
|
|
|
|
|
} else {
|
|
|
|
|
return proto.OperationFailed, "set redis with expire failed"
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return proto.ParameterError, "expire time can not be negative"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetToolRedis(key string) (code int, message string) {
|
|
|
|
|
val := worker.GetRedis(key)
|
|
|
|
|
if val == "" {
|
|
|
|
|
return proto.OperationFailed, "get redis failed"
|
|
|
|
|
} else {
|
|
|
|
|
return proto.SuccessCode, val
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-21 17:16:38 +08:00
|
|
|
|
|
|
|
|
func GetAllRedis() (code int, msg string, data []worker.RedisInfo) {
|
|
|
|
|
data, err := worker.GetAllRedisInfo()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return proto.OperationFailed, err.Error(), nil
|
|
|
|
|
}
|
|
|
|
|
return proto.SuccessCode, "success", data
|
|
|
|
|
}
|