forked from mirror/redis
Handle -1 in DurationCmd
This commit is contained in:
parent
458982a440
commit
c208a17dfc
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
||||||
all: testdeps
|
all: testdeps
|
||||||
go test ./...
|
go test ./...
|
||||||
go test ./... -short -race
|
go test ./... -short -race
|
||||||
go test ./... -run=NONE -bench=.
|
go test ./... -run=NONE -bench=. -benchmem
|
||||||
env GOOS=linux GOARCH=386 go test ./...
|
env GOOS=linux GOARCH=386 go test ./...
|
||||||
go vet
|
go vet
|
||||||
go get github.com/gordonklaus/ineffassign
|
go get github.com/gordonklaus/ineffassign
|
||||||
|
|
|
@ -439,7 +439,14 @@ func (cmd *DurationCmd) readReply(rd *proto.Reader) error {
|
||||||
if cmd.err != nil {
|
if cmd.err != nil {
|
||||||
return cmd.err
|
return cmd.err
|
||||||
}
|
}
|
||||||
|
switch n {
|
||||||
|
// -2 if the key does not exist
|
||||||
|
// -1 if the key exists but has no associated expire
|
||||||
|
case -2, -1:
|
||||||
|
cmd.val = time.Duration(n)
|
||||||
|
default:
|
||||||
cmd.val = time.Duration(n) * cmd.precision
|
cmd.val = time.Duration(n) * cmd.precision
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -374,7 +374,11 @@ var _ = Describe("Commands", func() {
|
||||||
|
|
||||||
ttl = client.TTL("key")
|
ttl = client.TTL("key")
|
||||||
Expect(ttl.Err()).NotTo(HaveOccurred())
|
Expect(ttl.Err()).NotTo(HaveOccurred())
|
||||||
Expect(ttl.Val() < 0).To(Equal(true))
|
Expect(ttl.Val()).To(Equal(time.Duration(-1)))
|
||||||
|
|
||||||
|
ttl = client.TTL("nonexistent_key")
|
||||||
|
Expect(ttl.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(ttl.Val()).To(Equal(time.Duration(-2)))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should ExpireAt", func() {
|
It("should ExpireAt", func() {
|
||||||
|
|
Loading…
Reference in New Issue