Files
aiops/backend/pkg/redis/redka.go
T
attacker 24f955832e feat: 发布权限 RBAC + PipelineEditor 修复 + 菜单优化
- 新增 DeployRBAC 页面: Jenkins-style Item Role 权限管理
  - 正则匹配流水线 code,实时命中预览
  - 内置用户分配面板,无需跳转系统管理
  - 支持创建/编辑/删除/启用禁用 Item Role
- 修复 PipelineEditor 成员管理 http 双解包 bug
- 修复 PipelineManager 前端 code 路由迁移(delete/trigger/stop/loadRuns)
- 新增批量删除流水线运行记录 API
- Sidebar: 应用发布下新增「发布权限」, 仓库认证→发布配置, 移除用户组
- 恢复系统管理菜单(不受发布权限改动影响)
- 后端 ItemRole CRUD handler + 正则匹配中间件已就绪
2026-06-21 05:26:01 +00:00

120 lines
2.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// redka 内嵌 Redis 兼容存储实现(v0.2.x API)
// 使用 github.com/nalgeon/redka — 基于 SQLite 的 Redis 替代方案 // Logan.Li
// 零外部依赖,数据存在本地文件中,非常适合独立二进制部署
package redis
import (
"context"
"fmt"
"time"
"github.com/nalgeon/redka"
)
// redkaCache 基于 Redka v0.2.x 的缓存实现 // Logan.Li
type redkaCache struct {
db *redka.DB
}
func newRedka(cfg Config) (Cache, error) {
dataDir := cfg.DataDir
if dataDir == "" {
dataDir = "data/redka"
}
// Redka v0.2.x: Open(path, opts) // Logan.Li
db, err := redka.Open(dataDir+"/redka.db", nil)
if err != nil {
return nil, err
}
return &redkaCache{db: db}, nil
}
func (r *redkaCache) Get(ctx context.Context, key string) (string, error) {
// Redka v0.2.x: Str().Get() 返回 core.Value // Logan.Li
val, err := r.db.Str().Get(key)
if err == redka.ErrNotFound {
return "", nil
}
if err != nil {
return "", err
}
return val.String(), nil
}
func (r *redkaCache) Set(ctx context.Context, key string, value string, expiration time.Duration) error {
// Redka v0.2.x: Str().Set() 返回 error // Logan.Li
if err := r.db.Str().Set(key, value); err != nil {
return err
}
if expiration > 0 {
_, err := r.db.Key().Expire(key, expiration)
return err
}
return nil
}
func (r *redkaCache) Del(ctx context.Context, keys ...string) error {
for _, key := range keys {
if _, err := r.db.Key().Delete(key); err != nil {
return err
}
}
return nil
}
func (r *redkaCache) Exists(ctx context.Context, keys ...string) (int64, error) {
var count int64
for _, key := range keys {
ok, err := r.db.Key().Exists(key)
if err != nil {
return 0, err
}
if ok {
count++
}
}
return count, nil
}
func (r *redkaCache) Expire(ctx context.Context, key string, expiration time.Duration) error {
ok, err := r.db.Key().Expire(key, expiration)
if err != nil {
return err
}
if !ok {
return redka.ErrNotFound
}
return nil
}
func (r *redkaCache) Ping(ctx context.Context) error {
// Redka 始终可用(内嵌数据库)// Logan.Li
return nil
}
func (r *redkaCache) Close() error {
return r.db.Close()
}
var errSortedSetNotSupported = fmt.Errorf("sorted set operations are not supported by the redka backend; use go-redis (driver=redis) instead")
func (r *redkaCache) ZAdd(ctx context.Context, key string, member SortedSetMember) error {
return errSortedSetNotSupported
}
func (r *redkaCache) ZRangeByScore(ctx context.Context, key string, min, max string) ([]SortedSetMember, error) {
return nil, errSortedSetNotSupported
}
func (r *redkaCache) ZRemRangeByScore(ctx context.Context, key string, min, max string) error {
return errSortedSetNotSupported
}
var errPubSubNotSupported = fmt.Errorf("Pub/Sub is not supported by the redka backend; use go-redis (driver=redis)")
func (r *redkaCache) Publish(ctx context.Context, channel string, message string) error {
return errPubSubNotSupported
}