44 lines
911 B
Go
44 lines
911 B
Go
package redisrepo
|
|
|
|
import (
|
|
"amor/common"
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
func GetUserBalance(userID int64) (balance int64, err error) {
|
|
balance, err = common.Redis.Get(context.Background(), fmt.Sprintf(common.MEMBER_BALANCE, userID)).Int64()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func UpdateUserBalance(userID int64, balance int64) (err error) {
|
|
err = common.Redis.Set(context.Background(), fmt.Sprintf(common.MEMBER_BALANCE, userID), balance, -1).Err()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func SubUserBalance(userID int64, amount int64) (err error) {
|
|
err = common.Redis.IncrBy(context.Background(), fmt.Sprintf(common.MEMBER_BALANCE, userID), -amount).Err()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func AddUserBalance(userID int64, amount int64) (err error) {
|
|
err = common.Redis.IncrBy(context.Background(), fmt.Sprintf(common.MEMBER_BALANCE, userID), amount).Err()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|