mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Set client name in HELLO RESP handshake (#3294)
This commit is contained in:
@ -186,6 +186,32 @@ var _ = Describe("Client", func() {
|
||||
Expect(val).Should(ContainSubstring("name=hi"))
|
||||
})
|
||||
|
||||
It("should attempt to set client name in HELLO", func() {
|
||||
opt := redisOptions()
|
||||
opt.ClientName = "hi"
|
||||
db := redis.NewClient(opt)
|
||||
|
||||
defer func() {
|
||||
Expect(db.Close()).NotTo(HaveOccurred())
|
||||
}()
|
||||
|
||||
// Client name should be already set on any successfully initialized connection
|
||||
name, err := db.ClientGetName(ctx).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(name).Should(Equal("hi"))
|
||||
|
||||
// HELLO should be able to explicitly overwrite the client name
|
||||
conn := db.Conn()
|
||||
hello, err := conn.Hello(ctx, 3, "", "", "hi2").Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(hello["proto"]).Should(Equal(int64(3)))
|
||||
name, err = conn.ClientGetName(ctx).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(name).Should(Equal("hi2"))
|
||||
err = conn.Close()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("should client PROTO 2", func() {
|
||||
opt := redisOptions()
|
||||
opt.Protocol = 2
|
||||
|
Reference in New Issue
Block a user