storage

package
v0.0.0-...-15e837a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RedisKeyConversation = "conversation:%d" // 会话的键
	RedisKeyJWT          = "jwt:%s"          // JWT 的键
)

RedisKey 用于存储 Redis 的键模板

View Source
const (
	CreateTableUsers = `` /* 182-byte string literal not displayed */

	CreateTableConversations = `` /* 275-byte string literal not displayed */

	InsertConversation = `
        INSERT INTO conversations (id, title, user_id, create_time) 
		VALUES (?, ?, ?, ?);`

	DeleteConversation = `
        DELETE FROM conversations 
        WHERE id = ? AND user_id = ?;`

	FetchConversations = `
        SELECT id, title, create_time
		FROM conversations 
		WHERE user_id = ? 
		ORDER BY ROWID DESC;`
)

SQLiteSQL 用于存储 SQLite 的 SQL 语句

Variables

This section is empty.

Functions

func CacheJWT

func CacheJWT(tokenStr string, userID int64, ttl time.Duration) error

CacheJWT 将 Token 存入 Redis

func DeleteConversationFromDB

func DeleteConversationFromDB(userID int64, conversationID int64) error

DeleteConversationFromDB 从数据库中删除会话元信息

func DeleteConversationFromRedis

func DeleteConversationFromRedis(conversationID int64) error

DeleteConversationFromRedis 从 Redis 中删除完整会话

func FetchConversationsByUserID

func FetchConversationsByUserID(userID int64) ([]*models.Conversation, error)

FetchConversationsByUserID 从数据库中获取指定用户的所有会话

func GenerateRedisKeyConversation

func GenerateRedisKeyConversation(conversationID int64) string

GenerateRedisKeyConversation 生成会话的 Redis 键

func GenerateRedisKeyJWT

func GenerateRedisKeyJWT(token string) string

GenerateRedisKeyJWT 生成 JWT 的 Redis 键

func GetCachedJWT

func GetCachedJWT(tokenStr string) (map[string]interface{}, error)

GetCachedJWT 从 Redis 中获取缓存的 Token

func GetConversationFromRedis

func GetConversationFromRedis(conversationID int64) (*models.Conversation, error)

GetConversationFromRedis 从 Redis 获取完整会话

func GetDB

func GetDB() *sql.DB

func InitializeRedis

func InitializeRedis() error

InitializeRedis 初始化 Redis 客户端

func InitializeSQLite

func InitializeSQLite() error

InitializeSQLite 初始化 SQLite 数据库

func SaveConversationToDB

func SaveConversationToDB(userID int64, conversation *models.Conversation) error

SaveConversationToDB 将会话保存到数据库

func SaveConversationToRedis

func SaveConversationToRedis(conversation *models.Conversation) error

SaveConversationToRedis 保存完整会话到 Redis

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL