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 } }