35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package redisrepo
|
|
|
|
import (
|
|
"amor/common"
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
)
|
|
|
|
func SetGroupGPTModel(ctx context.Context, groupID int64, model string) (err error) {
|
|
return common.Redis.Set(ctx, fmt.Sprintf(common.GPT_GROUP_MODEL, groupID), model, 0).Err()
|
|
}
|
|
|
|
func GetGroupGPTModel(ctx context.Context, groupID int64) (model string, err error) {
|
|
return common.Redis.Get(ctx, fmt.Sprintf(common.GPT_GROUP_MODEL, groupID)).Result()
|
|
}
|
|
|
|
func SetGroupGPTState(ctx context.Context, groupID int64, state int) (err error) {
|
|
return common.Redis.Set(ctx, fmt.Sprintf(common.GPT_GROUP_STATE, groupID), state, 0).Err()
|
|
}
|
|
|
|
func GetGroupGPTState(ctx context.Context, groupID int64) (state int, err error) {
|
|
key := fmt.Sprintf(common.GPT_GROUP_STATE, groupID)
|
|
val, err := common.Redis.Exists(ctx, key).Result()
|
|
if err != nil {
|
|
log.Printf("GetGroupGPTState err: %v", err)
|
|
return
|
|
}
|
|
if val != 1 {
|
|
SetGroupGPTState(ctx, groupID, common.GPT_STATE_DISABLE)
|
|
return
|
|
}
|
|
return common.Redis.Get(ctx, fmt.Sprintf(common.GPT_GROUP_STATE, groupID)).Int()
|
|
}
|