1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Marshal time as RFC3339. Add StringCmd.Time helper.

This commit is contained in:
Vladimir Mihailenco
2019-07-25 12:21:12 +03:00
parent 6bc7daa5b1
commit 0e7fb3b12d
5 changed files with 51 additions and 5 deletions

View File

@ -1,6 +1,8 @@
package redis_test
import (
"time"
"github.com/go-redis/redis"
. "github.com/onsi/ginkgo"
@ -67,4 +69,19 @@ var _ = Describe("Cmd", func() {
Expect(err).NotTo(HaveOccurred())
Expect(val).To(Equal(f))
})
It("supports time.Time", func() {
tm := time.Date(2019, 01, 01, 0, 0, 0, 0, time.UTC)
err := client.Set("time_key", tm, 0).Err()
Expect(err).NotTo(HaveOccurred())
s, err := client.Get("time_key").Result()
Expect(err).NotTo(HaveOccurred())
Expect(s).To(Equal("2019-01-01T00:00:00Z"))
tm2, err := client.Get("time_key").Time()
Expect(err).NotTo(HaveOccurred())
Expect(tm2).To(BeTemporally("==", tm))
})
})