From beabb6eeb96d7b2903e43ef590dc42d1fd39711b Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Sun, 4 Feb 2024 11:56:49 +0200 Subject: [PATCH 1/3] Send Client SetInfo via pipe --- redis.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/redis.go b/redis.go index 4dd862b84..02a7a23d1 100644 --- a/redis.go +++ b/redis.go @@ -312,17 +312,6 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { // difficult to rely on error strings to determine all results. return err } - if !c.opt.DisableIndentity { - libName := "" - libVer := Version() - if c.opt.IdentitySuffix != "" { - libName = c.opt.IdentitySuffix - } - libInfo := LibraryInfo{LibName: &libName} - conn.ClientSetInfo(ctx, libInfo) - libInfo = LibraryInfo{LibVer: &libVer} - conn.ClientSetInfo(ctx, libInfo) - } _, err := conn.Pipelined(ctx, func(pipe Pipeliner) error { if !auth && password != "" { if username != "" { @@ -344,6 +333,18 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { pipe.ClientSetName(ctx, c.opt.ClientName) } + if !c.opt.DisableIndentity { + libName := "" + libVer := Version() + if c.opt.IdentitySuffix != "" { + libName = c.opt.IdentitySuffix + } + libInfo := LibraryInfo{LibName: &libName} + pipe.ClientSetInfo(ctx, libInfo) + libInfo = LibraryInfo{LibVer: &libVer} + pipe.ClientSetInfo(ctx, libInfo) + } + return nil }) if err != nil { From a118fe69df13ede974ac9bff50123c577cf9e1af Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Mon, 5 Feb 2024 13:42:51 +0200 Subject: [PATCH 2/3] Fix ACL test --- commands_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands_test.go b/commands_test.go index 3d2ebf514..ea53c003f 100644 --- a/commands_test.go +++ b/commands_test.go @@ -2100,7 +2100,7 @@ var _ = Describe("Commands", func() { logEntries, err := client.ACLLog(ctx, 10).Result() Expect(err).NotTo(HaveOccurred()) - Expect(len(logEntries)).To(Equal(4)) + Expect(len(logEntries)).To(Equal(1)) for _, entry := range logEntries { Expect(entry.Reason).To(Equal("command")) @@ -2116,7 +2116,7 @@ var _ = Describe("Commands", func() { limitedLogEntries, err := client.ACLLog(ctx, 2).Result() Expect(err).NotTo(HaveOccurred()) - Expect(len(limitedLogEntries)).To(Equal(2)) + Expect(len(limitedLogEntries)).To(Equal(1)) }) It("should ACL LOG RESET", Label("NonRedisEnterprise"), func() { From 4822f5c6b7670c3748489be250fe8e04bcaba833 Mon Sep 17 00:00:00 2001 From: ofekshenawa Date: Thu, 15 Feb 2024 00:05:48 +0200 Subject: [PATCH 3/3] Add client set info to acl command rules --- redis.go | 17 ++--------------- sentinel_test.go | 2 +- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/redis.go b/redis.go index a3b463e8c..33477b53a 100644 --- a/redis.go +++ b/redis.go @@ -313,17 +313,6 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { return err } - if !c.opt.DisableIndentity { - libName := "" - libVer := Version() - - if c.opt.IdentitySuffix != "" { - libName = c.opt.IdentitySuffix - } - conn.ClientSetInfo(ctx, WithLibraryName(libName)) - conn.ClientSetInfo(ctx, WithLibraryVersion(libVer)) - } - _, err := conn.Pipelined(ctx, func(pipe Pipeliner) error { if !auth && password != "" { if username != "" { @@ -351,10 +340,8 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { if c.opt.IdentitySuffix != "" { libName = c.opt.IdentitySuffix } - libInfo := LibraryInfo{LibName: &libName} - pipe.ClientSetInfo(ctx, libInfo) - libInfo = LibraryInfo{LibVer: &libVer} - pipe.ClientSetInfo(ctx, libInfo) + pipe.ClientSetInfo(ctx, WithLibraryName(libName)) + pipe.ClientSetInfo(ctx, WithLibraryVersion(libVer)) } return nil diff --git a/sentinel_test.go b/sentinel_test.go index 4c013f05f..8bc6c5785 100644 --- a/sentinel_test.go +++ b/sentinel_test.go @@ -324,7 +324,7 @@ var _ = Describe("SentinelAclAuth", func() { BeforeEach(func() { authCmd := redis.NewStatusCmd(ctx, "ACL", "SETUSER", aclSentinelUsername, "ON", ">"+aclSentinelPassword, "-@all", "+auth", "+client|getname", "+client|id", "+client|setname", - "+command", "+hello", "+ping", "+role", "+sentinel|get-master-addr-by-name", "+sentinel|master", + "+command", "+hello", "+ping", "+client|setinfo", "+role", "+sentinel|get-master-addr-by-name", "+sentinel|master", "+sentinel|myid", "+sentinel|replicas", "+sentinel|sentinels") for _, process := range sentinels() {