...

Source file src/github.com/redis/go-redis/v9/acl_commands.go

Documentation: github.com/redis/go-redis/v9

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

View as plain text