Skip to content

Commit 0faa77c

Browse files
author
wujideng
committed
feat: add acl support and command test
(cherry picked from commit a624cc4)
1 parent ae5434c commit 0faa77c

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

acl_commands.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ type ACLCmdable interface {
88
ACLLog(ctx context.Context, count int64) *ACLLogCmd
99
ACLLogReset(ctx context.Context) *StatusCmd
1010

11+
ACLGenPass(ctx context.Context, bit int) *StringCmd
12+
1113
ACLSetUser(ctx context.Context, username string, rules ...string) *StatusCmd
1214
ACLDelUser(ctx context.Context, username string) *IntCmd
15+
ACLUsers(ctx context.Context) *StringSliceCmd
16+
ACLWhoAmI(ctx context.Context) *StringCmd
1317
ACLList(ctx context.Context) *StringSliceCmd
1418

1519
ACLCat(ctx context.Context) *StringSliceCmd
@@ -65,6 +69,24 @@ func (c cmdable) ACLSetUser(ctx context.Context, username string, rules ...strin
6569
return cmd
6670
}
6771

72+
func (c cmdable) ACLGenPass(ctx context.Context, bit int) *StringCmd {
73+
cmd := NewStringCmd(ctx, "acl", "genpass")
74+
_ = c(ctx, cmd)
75+
return cmd
76+
}
77+
78+
func (c cmdable) ACLUsers(ctx context.Context) *StringSliceCmd {
79+
cmd := NewStringSliceCmd(ctx, "acl", "users")
80+
_ = c(ctx, cmd)
81+
return cmd
82+
}
83+
84+
func (c cmdable) ACLWhoAmI(ctx context.Context) *StringCmd {
85+
cmd := NewStringCmd(ctx, "acl", "whoami")
86+
_ = c(ctx, cmd)
87+
return cmd
88+
}
89+
6890
func (c cmdable) ACLList(ctx context.Context) *StringSliceCmd {
6991
cmd := NewStringSliceCmd(ctx, "acl", "list")
7092
_ = c(ctx, cmd)

acl_commands_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ var _ = Describe("ACL user commands", Label("NonRedisEnterprise"), func() {
9292
Expect(err).NotTo(HaveOccurred())
9393
Expect(res).To(HaveLen(1))
9494
Expect(res[0]).To(ContainSubstring("default"))
95+
96+
res, err = client.ACLUsers(ctx).Result()
97+
Expect(err).NotTo(HaveOccurred())
98+
Expect(res).To(HaveLen(1))
99+
Expect(res[0]).To(Equal("default"))
100+
101+
res1, err := client.ACLWhoAmI(ctx).Result()
102+
Expect(err).NotTo(HaveOccurred())
103+
Expect(res1).To(Equal("default"))
104+
})
105+
106+
It("gen password", func() {
107+
password, err := client.ACLGenPass(ctx, 0).Result()
108+
Expect(err).NotTo(HaveOccurred())
109+
Expect(password).NotTo(BeEmpty())
95110
})
96111

97112
It("setuser and deluser", func() {

commands_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,25 @@ var _ = Describe("Commands", func() {
199199
Expect(r.Val()).To(Equal(int64(0)))
200200
})
201201

202+
It("should ClientKillByFilter with kill myself", func() {
203+
opt := redisOptions()
204+
opt.ClientName = "killmyid"
205+
db := redis.NewClient(opt)
206+
207+
defer func() {
208+
Expect(db.Close()).NotTo(HaveOccurred())
209+
}()
210+
211+
myid := db.ClientID(ctx).Val()
212+
killed := client.ClientKillByFilter(ctx, "ID", strconv.FormatInt(myid, 10))
213+
Expect(killed.Err()).NotTo(HaveOccurred())
214+
Expect(killed.Val()).To(BeNumerically("==", 1))
215+
216+
val, err := client.ClientList(ctx).Result()
217+
Expect(err).NotTo(HaveOccurred())
218+
Expect(val).ShouldNot(ContainSubstring("name=killmyid"))
219+
})
220+
202221
It("should ClientKillByFilter with MAXAGE", Label("NonRedisEnterprise"), func() {
203222
SkipBeforeRedisVersion(7.4, "doesn't work with older redis stack images")
204223
var s []string

0 commit comments

Comments
 (0)