mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-25 18:30:08 +08:00
- 后端实现:新增Redis客户端接口与go-redis实现,支持SSH隧道连接 - API方法:新增21个Redis操作API(连接/Key/Value/命令执行等) - 连接配置:ConnectionModal支持Redis类型,自动识别端口与认证方式 - 数据浏览:RedisViewer组件支持Key列表展示、类型识别与分页加载 - 值编辑器:支持String/Hash/List/Set/ZSet五种数据类型的查看与编辑 - 二进制处理:自动检测二进制数据并以十六进制格式展示 - 命令终端:RedisCommandEditor支持多行命令执行与结果展示 - 交互优化:JSON语法高亮编辑、一键复制值、面板宽度可调整
91 lines
2.7 KiB
Go
91 lines
2.7 KiB
Go
package redis
|
|
|
|
import "GoNavi-Wails/internal/connection"
|
|
|
|
// RedisValue represents a Redis value with its type and metadata
|
|
type RedisValue struct {
|
|
Type string `json:"type"` // string, hash, list, set, zset
|
|
TTL int64 `json:"ttl"` // TTL in seconds, -1 means no expiry, -2 means key doesn't exist
|
|
Value interface{} `json:"value"` // The actual value
|
|
Length int64 `json:"length"` // Length/size of the value
|
|
}
|
|
|
|
// RedisDBInfo represents information about a Redis database
|
|
type RedisDBInfo struct {
|
|
Index int `json:"index"` // Database index (0-15)
|
|
Keys int64 `json:"keys"` // Number of keys in this database
|
|
}
|
|
|
|
// RedisKeyInfo represents information about a Redis key
|
|
type RedisKeyInfo struct {
|
|
Key string `json:"key"`
|
|
Type string `json:"type"`
|
|
TTL int64 `json:"ttl"`
|
|
}
|
|
|
|
// RedisScanResult represents the result of a SCAN operation
|
|
type RedisScanResult struct {
|
|
Keys []RedisKeyInfo `json:"keys"`
|
|
Cursor uint64 `json:"cursor"`
|
|
}
|
|
|
|
// RedisClient defines the interface for Redis operations
|
|
type RedisClient interface {
|
|
// Connection management
|
|
Connect(config connection.ConnectionConfig) error
|
|
Close() error
|
|
Ping() error
|
|
|
|
// Key operations
|
|
ScanKeys(pattern string, cursor uint64, count int64) (*RedisScanResult, error)
|
|
GetKeyType(key string) (string, error)
|
|
GetTTL(key string) (int64, error)
|
|
SetTTL(key string, ttl int64) error
|
|
DeleteKeys(keys []string) (int64, error)
|
|
RenameKey(oldKey, newKey string) error
|
|
KeyExists(key string) (bool, error)
|
|
|
|
// Value operations
|
|
GetValue(key string) (*RedisValue, error)
|
|
|
|
// String operations
|
|
GetString(key string) (string, error)
|
|
SetString(key, value string, ttl int64) error
|
|
|
|
// Hash operations
|
|
GetHash(key string) (map[string]string, error)
|
|
SetHashField(key, field, value string) error
|
|
DeleteHashField(key string, fields ...string) error
|
|
|
|
// List operations
|
|
GetList(key string, start, stop int64) ([]string, error)
|
|
ListPush(key string, values ...string) error
|
|
ListSet(key string, index int64, value string) error
|
|
|
|
// Set operations
|
|
GetSet(key string) ([]string, error)
|
|
SetAdd(key string, members ...string) error
|
|
SetRemove(key string, members ...string) error
|
|
|
|
// Sorted Set operations
|
|
GetZSet(key string, start, stop int64) ([]ZSetMember, error)
|
|
ZSetAdd(key string, members ...ZSetMember) error
|
|
ZSetRemove(key string, members ...string) error
|
|
|
|
// Command execution
|
|
ExecuteCommand(args []string) (interface{}, error)
|
|
|
|
// Server information
|
|
GetServerInfo() (map[string]string, error)
|
|
GetDatabases() ([]RedisDBInfo, error)
|
|
SelectDB(index int) error
|
|
GetCurrentDB() int
|
|
FlushDB() error
|
|
}
|
|
|
|
// ZSetMember represents a member in a sorted set
|
|
type ZSetMember struct {
|
|
Member string `json:"member"`
|
|
Score float64 `json:"score"`
|
|
}
|