From 412baf447b1b47109bc4c6b5e50ea7d53447ce8f Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 11 Jul 2015 12:23:04 +0300 Subject: [PATCH] Add RestoreReplace. --- commands.go | 12 ++++++++++++ commands_test.go | 47 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/commands.go b/commands.go index 56167d50..c9a3a351 100644 --- a/commands.go +++ b/commands.go @@ -249,6 +249,18 @@ func (c *commandable) Restore(key string, ttl int64, value string) *StatusCmd { return cmd } +func (c *commandable) RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd { + cmd := NewStatusCmd( + "RESTORE", + key, + formatMs(ttl), + value, + "REPLACE", + ) + c.Process(cmd) + return cmd +} + type Sort struct { By string Offset, Count float64 diff --git a/commands_test.go b/commands_test.go index 0e0405ed..ae0535ee 100644 --- a/commands_test.go +++ b/commands_test.go @@ -451,27 +451,46 @@ var _ = Describe("Commands", func() { }) It("should Restore", func() { - set := client.Set("key", "hello", 0) - Expect(set.Err()).NotTo(HaveOccurred()) - Expect(set.Val()).To(Equal("OK")) + err := client.Set("key", "hello", 0).Err() + Expect(err).NotTo(HaveOccurred()) dump := client.Dump("key") Expect(dump.Err()).NotTo(HaveOccurred()) - del := client.Del("key") - Expect(del.Err()).NotTo(HaveOccurred()) + err = client.Del("key").Err() + Expect(err).NotTo(HaveOccurred()) - restore := client.Restore("key", 0, dump.Val()) - Expect(restore.Err()).NotTo(HaveOccurred()) - Expect(restore.Val()).To(Equal("OK")) + restore, err := client.Restore("key", 0, dump.Val()).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(restore).To(Equal("OK")) - type_ := client.Type("key") - Expect(type_.Err()).NotTo(HaveOccurred()) - Expect(type_.Val()).To(Equal("string")) + type_, err := client.Type("key").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(type_).To(Equal("string")) - lRange := client.Get("key") - Expect(lRange.Err()).NotTo(HaveOccurred()) - Expect(lRange.Val()).To(Equal("hello")) + val, err := client.Get("key").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(val).To(Equal("hello")) + }) + + It("should RestoreReplace", func() { + err := client.Set("key", "hello", 0).Err() + Expect(err).NotTo(HaveOccurred()) + + dump := client.Dump("key") + Expect(dump.Err()).NotTo(HaveOccurred()) + + restore, err := client.RestoreReplace("key", 0, dump.Val()).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(restore).To(Equal("OK")) + + type_, err := client.Type("key").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(type_).To(Equal("string")) + + val, err := client.Get("key").Result() + Expect(err).NotTo(HaveOccurred()) + Expect(val).To(Equal("hello")) }) It("should Sort", func() {