Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

90 righe
2.3 KiB

  1. package redis
  2. import "context"
  3. type ACLCmdable interface {
  4. ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd
  5. ACLLog(ctx context.Context, count int64) *ACLLogCmd
  6. ACLLogReset(ctx context.Context) *StatusCmd
  7. ACLSetUser(ctx context.Context, username string, rules ...string) *StatusCmd
  8. ACLDelUser(ctx context.Context, username string) *IntCmd
  9. ACLList(ctx context.Context) *StringSliceCmd
  10. ACLCat(ctx context.Context) *StringSliceCmd
  11. ACLCatArgs(ctx context.Context, options *ACLCatArgs) *StringSliceCmd
  12. }
  13. type ACLCatArgs struct {
  14. Category string
  15. }
  16. func (c cmdable) ACLDryRun(ctx context.Context, username string, command ...interface{}) *StringCmd {
  17. args := make([]interface{}, 0, 3+len(command))
  18. args = append(args, "acl", "dryrun", username)
  19. args = append(args, command...)
  20. cmd := NewStringCmd(ctx, args...)
  21. _ = c(ctx, cmd)
  22. return cmd
  23. }
  24. func (c cmdable) ACLLog(ctx context.Context, count int64) *ACLLogCmd {
  25. args := make([]interface{}, 0, 3)
  26. args = append(args, "acl", "log")
  27. if count > 0 {
  28. args = append(args, count)
  29. }
  30. cmd := NewACLLogCmd(ctx, args...)
  31. _ = c(ctx, cmd)
  32. return cmd
  33. }
  34. func (c cmdable) ACLLogReset(ctx context.Context) *StatusCmd {
  35. cmd := NewStatusCmd(ctx, "acl", "log", "reset")
  36. _ = c(ctx, cmd)
  37. return cmd
  38. }
  39. func (c cmdable) ACLDelUser(ctx context.Context, username string) *IntCmd {
  40. cmd := NewIntCmd(ctx, "acl", "deluser", username)
  41. _ = c(ctx, cmd)
  42. return cmd
  43. }
  44. func (c cmdable) ACLSetUser(ctx context.Context, username string, rules ...string) *StatusCmd {
  45. args := make([]interface{}, 3+len(rules))
  46. args[0] = "acl"
  47. args[1] = "setuser"
  48. args[2] = username
  49. for i, rule := range rules {
  50. args[i+3] = rule
  51. }
  52. cmd := NewStatusCmd(ctx, args...)
  53. _ = c(ctx, cmd)
  54. return cmd
  55. }
  56. func (c cmdable) ACLList(ctx context.Context) *StringSliceCmd {
  57. cmd := NewStringSliceCmd(ctx, "acl", "list")
  58. _ = c(ctx, cmd)
  59. return cmd
  60. }
  61. func (c cmdable) ACLCat(ctx context.Context) *StringSliceCmd {
  62. cmd := NewStringSliceCmd(ctx, "acl", "cat")
  63. _ = c(ctx, cmd)
  64. return cmd
  65. }
  66. func (c cmdable) ACLCatArgs(ctx context.Context, options *ACLCatArgs) *StringSliceCmd {
  67. // if there is a category passed, build new cmd, if there isn't - use the ACLCat method
  68. if options != nil && options.Category != "" {
  69. cmd := NewStringSliceCmd(ctx, "acl", "cat", options.Category)
  70. _ = c(ctx, cmd)
  71. return cmd
  72. }
  73. return c.ACLCat(ctx)
  74. }