forked from mirror/redis
add new command Touch and SwapDB
This commit is contained in:
parent
32f020f1fa
commit
daab7c60d0
19
commands.go
19
commands.go
|
@ -73,6 +73,7 @@ type Cmdable interface {
|
|||
Sort(key string, sort *Sort) *StringSliceCmd
|
||||
SortStore(key, store string, sort *Sort) *IntCmd
|
||||
SortInterfaces(key string, sort *Sort) *SliceCmd
|
||||
Touch(keys ...string) *IntCmd
|
||||
TTL(key string) *DurationCmd
|
||||
Type(key string) *StatusCmd
|
||||
Scan(cursor uint64, match string, count int64) *ScanCmd
|
||||
|
@ -253,6 +254,7 @@ type StatefulCmdable interface {
|
|||
Cmdable
|
||||
Auth(password string) *StatusCmd
|
||||
Select(index int) *StatusCmd
|
||||
SwapDB(index1, index2 int) *StatusCmd
|
||||
ClientSetName(name string) *BoolCmd
|
||||
ReadOnly() *StatusCmd
|
||||
ReadWrite() *StatusCmd
|
||||
|
@ -317,6 +319,12 @@ func (c *statefulCmdable) Select(index int) *StatusCmd {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (c *statefulCmdable) SwapDB(index1, index2 int) *StatusCmd {
|
||||
cmd := NewStatusCmd("swapdb", index1, index2)
|
||||
c.process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
func (c *cmdable) Del(keys ...string) *IntCmd {
|
||||
|
@ -533,6 +541,17 @@ func (c *cmdable) SortInterfaces(key string, sort *Sort) *SliceCmd {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (c *cmdable) Touch(keys ...string) *IntCmd {
|
||||
args := make([]interface{}, len(keys)+1)
|
||||
args[0] = "touch"
|
||||
for i, key := range keys {
|
||||
args[i+1] = key
|
||||
}
|
||||
cmd := NewIntCmd(args...)
|
||||
c.process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *cmdable) TTL(key string) *DurationCmd {
|
||||
cmd := NewDurationCmd(time.Second, "ttl", key)
|
||||
c.process(cmd)
|
||||
|
|
|
@ -79,6 +79,16 @@ var _ = Describe("Commands", func() {
|
|||
Expect(sel.Val()).To(Equal("OK"))
|
||||
})
|
||||
|
||||
It("should SwapDB", func() {
|
||||
pipe := client.Pipeline()
|
||||
sel := pipe.SwapDB(1, 2)
|
||||
_, err := pipe.Exec()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(sel.Err()).NotTo(HaveOccurred())
|
||||
Expect(sel.Val()).To(Equal("OK"))
|
||||
})
|
||||
|
||||
It("should BgRewriteAOF", func() {
|
||||
Skip("flaky test")
|
||||
|
||||
|
@ -650,6 +660,20 @@ var _ = Describe("Commands", func() {
|
|||
Expect(els).To(Equal([]string{"1", "2"}))
|
||||
})
|
||||
|
||||
It("should Touch", func() {
|
||||
set1 := client.Set("touch1", "hello", 0)
|
||||
Expect(set1.Err()).NotTo(HaveOccurred())
|
||||
Expect(set1.Val()).To(Equal("OK"))
|
||||
|
||||
set2 := client.Set("touch2", "hello", 0)
|
||||
Expect(set2.Err()).NotTo(HaveOccurred())
|
||||
Expect(set2.Val()).To(Equal("OK"))
|
||||
|
||||
touch := client.Touch("touch1", "touch2", "touch3")
|
||||
Expect(touch.Err()).NotTo(HaveOccurred())
|
||||
Expect(touch.Val()).To(Equal(int64(2)))
|
||||
})
|
||||
|
||||
It("should TTL", func() {
|
||||
ttl := client.TTL("key")
|
||||
Expect(ttl.Err()).NotTo(HaveOccurred())
|
||||
|
|
Loading…
Reference in New Issue