“结论:初始阶段2w qps以内,完全不用做 cache aside”

generate API key

echo "chattyai_$(openssl rand -base64 40 | tr -dc A-Za-z0-9 | head -c 28)"

Create API record

// create chatty_ai record
INSERT INTO chattyai_rights (uid, token_quota, token_used, token_used_total, assistant_quota, assistant_used, gpt_4_access, api_access, subscription_date, subscription_update_date, subscription_end_date)
VALUES ('chattyai_xxxxxxxxx', 1000000, 0, 0, 15, 0, TRUE, TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

// create order record
manually add api, no order.

目标

type ChattyAIRights struct {
	ID                     uint64    `gorm:"column:id"`
	UID                    string    `gorm:"column:uid"`
	TokenQuota             int64     `gorm:"column:token_quota" json:"token_quota"`
	TokenUsed              int64     `gorm:"column:token_used" json:"token_used"`
	TokenUsedTotal         int64     `gorm:"column:token_used_total" json:"token_used_total"`
	ConversationQuota      int64     `gorm:"column:conversation_quota" json:"conversation_quota"`
	ConversationUsed       int64     `gorm:"column:conversation_used" json:"conversation_used"`
	ConversationUsedTotal  int64     `gorm:"column:conversation_used_total" json:"conversation_used_total"`
	AssistantQuota         int64     `gorm:"column:assistant_quota" json:"assistant_quota"`
	AssistantUsed          int64     `gorm:"column:assistant_used" json:"assistant_used"`
	GPT4Access             bool      `gorm:"column:gpt4_access" json:"gpt_4_access"`
	APIAccess              bool      `gorm:"column:api_access" json:"api_access"`
	SubscriptionDate       time.Time `gorm:"column:subscription_date" json:"subscription_date"` // subscription date means the first time when subscription occurred.
	SubscriptionUpdateDate time.Time `gorm:"column:subscription_update_date" json:"subscription_update_date"`
	SubscriptionEndDate    time.Time `gorm:"column:subscription_end_date" json:"subscription_end_date"`
	CreatedAt              time.Time `gorm:"column:created_at"`
	UpdatedAt              time.Time `gorm:"column:updated_at"`
}

cache aside

同步缓存,同步回写