mirror of https://github.com/go-redis/redis.git
Merge pull request #131 from go-redis/feature/restore-replace
Add RestoreReplace.
This commit is contained in:
commit
a16f70a722
12
commands.go
12
commands.go
|
@ -249,6 +249,18 @@ func (c *commandable) Restore(key string, ttl int64, value string) *StatusCmd {
|
||||||
return cmd
|
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 {
|
type Sort struct {
|
||||||
By string
|
By string
|
||||||
Offset, Count float64
|
Offset, Count float64
|
||||||
|
|
|
@ -451,27 +451,46 @@ var _ = Describe("Commands", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should Restore", func() {
|
It("should Restore", func() {
|
||||||
set := client.Set("key", "hello", 0)
|
err := client.Set("key", "hello", 0).Err()
|
||||||
Expect(set.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(set.Val()).To(Equal("OK"))
|
|
||||||
|
|
||||||
dump := client.Dump("key")
|
dump := client.Dump("key")
|
||||||
Expect(dump.Err()).NotTo(HaveOccurred())
|
Expect(dump.Err()).NotTo(HaveOccurred())
|
||||||
|
|
||||||
del := client.Del("key")
|
err = client.Del("key").Err()
|
||||||
Expect(del.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
restore := client.Restore("key", 0, dump.Val())
|
restore, err := client.Restore("key", 0, dump.Val()).Result()
|
||||||
Expect(restore.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(restore.Val()).To(Equal("OK"))
|
Expect(restore).To(Equal("OK"))
|
||||||
|
|
||||||
type_ := client.Type("key")
|
type_, err := client.Type("key").Result()
|
||||||
Expect(type_.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(type_.Val()).To(Equal("string"))
|
Expect(type_).To(Equal("string"))
|
||||||
|
|
||||||
lRange := client.Get("key")
|
val, err := client.Get("key").Result()
|
||||||
Expect(lRange.Err()).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(lRange.Val()).To(Equal("hello"))
|
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() {
|
It("should Sort", func() {
|
||||||
|
|
Loading…
Reference in New Issue