1
0
mirror of https://github.com/redis/go-redis.git synced 2025-06-14 01:21:30 +03:00

Update conn.UsedAt on Read/Write. Fixes #263.

This commit is contained in:
Vladimir Mihailenco
2016-03-02 13:26:05 +02:00
parent a4e4d1da06
commit 78d40d5bd7
3 changed files with 31 additions and 17 deletions

View File

@ -55,21 +55,19 @@ var _ = Describe("Client", func() {
It("should close", func() {
Expect(client.Close()).NotTo(HaveOccurred())
err := client.Ping().Err()
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("redis: client is closed"))
})
It("should close pubsub without closing the connection", func() {
It("should close pubsub without closing the client", func() {
pubsub := client.PubSub()
Expect(pubsub.Close()).NotTo(HaveOccurred())
_, err := pubsub.Receive()
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("redis: client is closed"))
Expect(client.Ping().Err()).NotTo(HaveOccurred())
})
It("should close multi without closing the connection", func() {
It("should close multi without closing the client", func() {
multi := client.Multi()
Expect(multi.Close()).NotTo(HaveOccurred())
@ -77,19 +75,19 @@ var _ = Describe("Client", func() {
multi.Ping()
return nil
})
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("redis: client is closed"))
Expect(client.Ping().Err()).NotTo(HaveOccurred())
})
It("should close pipeline without closing the connection", func() {
It("should close pipeline without closing the client", func() {
pipeline := client.Pipeline()
Expect(pipeline.Close()).NotTo(HaveOccurred())
pipeline.Ping()
_, err := pipeline.Exec()
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("redis: client is closed"))
Expect(client.Ping().Err()).NotTo(HaveOccurred())
})
@ -171,6 +169,23 @@ var _ = Describe("Client", func() {
err = client.Ping().Err()
Expect(err).NotTo(HaveOccurred())
})
It("should maintain conn.UsedAt", func() {
cn, _, err := client.Pool().Get()
Expect(err).NotTo(HaveOccurred())
Expect(cn.UsedAt).To(BeZero())
err = client.Pool().Put(cn)
Expect(err).NotTo(HaveOccurred())
Expect(cn.UsedAt).To(BeZero())
err = client.Ping().Err()
Expect(err).NotTo(HaveOccurred())
cn = client.Pool().First()
Expect(cn).NotTo(BeNil())
Expect(cn.UsedAt).To(BeTemporally("~", time.Now()))
})
})
//------------------------------------------------------------------------------