Skip to content

Commit

Permalink
Speed up connections by sending SetInfo via a pipeline (#2880)
Browse files Browse the repository at this point in the history
* Send Client SetInfo via pipe

* Fix ACL test

* Add client set info to acl command rules
  • Loading branch information
ofekshenawa committed Feb 15, 2024
1 parent 8afc2b9 commit 35de49a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions commands_test.go
Expand Up @@ -2105,7 +2105,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"))
Expand All @@ -2121,7 +2121,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() {
Expand Down
19 changes: 10 additions & 9 deletions redis.go
Expand Up @@ -312,16 +312,7 @@ 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
}
conn.ClientSetInfo(ctx, WithLibraryName(libName))
conn.ClientSetInfo(ctx, WithLibraryVersion(libVer))
}
_, err := conn.Pipelined(ctx, func(pipe Pipeliner) error {
if !auth && password != "" {
if username != "" {
Expand All @@ -343,6 +334,16 @@ 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
}
pipe.ClientSetInfo(ctx, WithLibraryName(libName))
pipe.ClientSetInfo(ctx, WithLibraryVersion(libVer))
}

return nil
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion sentinel_test.go
Expand Up @@ -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() {
Expand Down

0 comments on commit 35de49a

Please sign in to comment.