2026-05-20 07:01:08 +00:00
|
|
|
// Package redis provides a process-wide Redis client (one connection pool per Addr).
|
|
|
|
|
// Construct once in svc.ServiceContext and inject into model repositories / use cases.
|
|
|
|
|
package redis
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Client wraps go-zero Redis so all modules share the same connection pool.
|
|
|
|
|
type Client struct {
|
|
|
|
|
r *redis.Redis
|
feat(permission): add RBAC module with Casbin enforcement and policy reload
- Multi-tenant RBAC: permission catalog, roles, role-permission mapping,
user-role assignment, and external IdP role mapping (zitadel/ldap/scim).
- Casbin enforcer with Redis-backed adapter and Pub/Sub reload for
multi-instance policy sync; HTTP middleware enforces (tenant, role,
path, method) with platform admin bypass.
- /api/v1/permissions routes: catalog, me, policy/reload, roles CRUD,
role permissions, user roles, role mappings.
- New error scope (31) for Permission and biz code descriptions.
- Wire Permission module into ServiceContext, config, mongo-index, and
add cmd/permission-seed CLI plus etc/rbac.conf model.
- Redis client gains lazy PubSubClient helper (go-zero wrapper lacks Subscribe).
- Rewrite internal/model/member/README to cover Tenant/Member/Identity.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 08:47:35 +00:00
|
|
|
pubSubFields
|
2026-05-20 07:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewClient returns a shared Redis client, or (nil, nil) when Host is empty.
|
|
|
|
|
func NewClient(conf redis.RedisConf) (*Client, error) {
|
|
|
|
|
if conf.Host == "" {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
if err := conf.Validate(); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("redis: invalid config: %w", err)
|
|
|
|
|
}
|
|
|
|
|
return &Client{r: redis.MustNewRedis(conf)}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MustNewClient is like NewClient but panics on error (startup wiring).
|
|
|
|
|
func MustNewClient(conf redis.RedisConf) *Client {
|
|
|
|
|
c, err := NewClient(conf)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Zero returns the underlying go-zero Redis handle.
|
|
|
|
|
func (c *Client) Zero() *redis.Redis {
|
|
|
|
|
if c == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return c.r
|
|
|
|
|
}
|