Skip to content

Commit 35de49a

Browse files
authored
Speed up connections by sending SetInfo via a pipeline (redis#2880)
* Send Client SetInfo via pipe * Fix ACL test * Add client set info to acl command rules
1 parent 8afc2b9 commit 35de49a

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

commands_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ var _ = Describe("Commands", func() {
21052105

21062106
logEntries, err := client.ACLLog(ctx, 10).Result()
21072107
Expect(err).NotTo(HaveOccurred())
2108-
Expect(len(logEntries)).To(Equal(4))
2108+
Expect(len(logEntries)).To(Equal(1))
21092109

21102110
for _, entry := range logEntries {
21112111
Expect(entry.Reason).To(Equal("command"))
@@ -2121,7 +2121,7 @@ var _ = Describe("Commands", func() {
21212121

21222122
limitedLogEntries, err := client.ACLLog(ctx, 2).Result()
21232123
Expect(err).NotTo(HaveOccurred())
2124-
Expect(len(limitedLogEntries)).To(Equal(2))
2124+
Expect(len(limitedLogEntries)).To(Equal(1))
21252125
})
21262126

21272127
It("should ACL LOG RESET", Label("NonRedisEnterprise"), func() {

redis.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
312312
// difficult to rely on error strings to determine all results.
313313
return err
314314
}
315-
if !c.opt.DisableIndentity {
316-
libName := ""
317-
libVer := Version()
318315

319-
if c.opt.IdentitySuffix != "" {
320-
libName = c.opt.IdentitySuffix
321-
}
322-
conn.ClientSetInfo(ctx, WithLibraryName(libName))
323-
conn.ClientSetInfo(ctx, WithLibraryVersion(libVer))
324-
}
325316
_, err := conn.Pipelined(ctx, func(pipe Pipeliner) error {
326317
if !auth && password != "" {
327318
if username != "" {
@@ -343,6 +334,16 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
343334
pipe.ClientSetName(ctx, c.opt.ClientName)
344335
}
345336

337+
if !c.opt.DisableIndentity {
338+
libName := ""
339+
libVer := Version()
340+
if c.opt.IdentitySuffix != "" {
341+
libName = c.opt.IdentitySuffix
342+
}
343+
pipe.ClientSetInfo(ctx, WithLibraryName(libName))
344+
pipe.ClientSetInfo(ctx, WithLibraryVersion(libVer))
345+
}
346+
346347
return nil
347348
})
348349
if err != nil {

sentinel_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ var _ = Describe("SentinelAclAuth", func() {
324324
BeforeEach(func() {
325325
authCmd := redis.NewStatusCmd(ctx, "ACL", "SETUSER", aclSentinelUsername, "ON",
326326
">"+aclSentinelPassword, "-@all", "+auth", "+client|getname", "+client|id", "+client|setname",
327-
"+command", "+hello", "+ping", "+role", "+sentinel|get-master-addr-by-name", "+sentinel|master",
327+
"+command", "+hello", "+ping", "+client|setinfo", "+role", "+sentinel|get-master-addr-by-name", "+sentinel|master",
328328
"+sentinel|myid", "+sentinel|replicas", "+sentinel|sentinels")
329329

330330
for _, process := range sentinels() {

0 commit comments

Comments
 (0)