Add MemoryUsage

This commit is contained in:
Vladimir Mihailenco 2018-07-22 09:46:29 +03:00
parent 7c9aa65a40
commit ce9cfe9417
2 changed files with 41 additions and 10 deletions

View File

@ -62,6 +62,7 @@ type Cmdable interface {
TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)
TxPipeline() Pipeliner
Command() *CommandsInfoCmd
ClientGetName() *StringCmd
Echo(message interface{}) *StringCmd
Ping() *StatusCmd
@ -275,9 +276,9 @@ type Cmdable interface {
GeoRadiusByMemberRO(key, member string, query *GeoRadiusQuery) *GeoLocationCmd
GeoDist(key string, member1, member2, unit string) *FloatCmd
GeoHash(key string, members ...string) *StringSliceCmd
Command() *CommandsInfoCmd
ReadOnly() *StatusCmd
ReadWrite() *StatusCmd
MemoryUsage(key string, samples ...int) *IntCmd
}
type StatefulCmdable interface {
@ -355,6 +356,12 @@ func (c *statefulCmdable) SwapDB(index1, index2 int) *StatusCmd {
//------------------------------------------------------------------------------
func (c *cmdable) Command() *CommandsInfoCmd {
cmd := NewCommandsInfoCmd("command")
c.process(cmd)
return cmd
}
func (c *cmdable) Del(keys ...string) *IntCmd {
args := make([]interface{}, 1+len(keys))
args[0] = "del"
@ -2301,8 +2308,15 @@ func (c *cmdable) GeoPos(key string, members ...string) *GeoPosCmd {
//------------------------------------------------------------------------------
func (c *cmdable) Command() *CommandsInfoCmd {
cmd := NewCommandsInfoCmd("command")
func (c *cmdable) MemoryUsage(key string, samples ...int) *IntCmd {
args := []interface{}{"memory", "usage", key}
if len(samples) > 0 {
if len(samples) != 1 {
panic("MemoryUsage expects single sample count")
}
args = append(args, "SAMPLES", samples[0])
}
cmd := NewIntCmd(args...)
c.process(cmd)
return cmd
}

View File

@ -244,14 +244,31 @@ var _ = Describe("Commands", func() {
Describe("debugging", func() {
It("should DebugObject", func() {
debug := client.DebugObject("foo")
Expect(debug.Err()).To(HaveOccurred())
Expect(debug.Err().Error()).To(Equal("ERR no such key"))
err := client.DebugObject("foo").Err()
Expect(err).To(MatchError("ERR no such key"))
client.Set("foo", "bar", 0)
debug = client.DebugObject("foo")
Expect(debug.Err()).NotTo(HaveOccurred())
Expect(debug.Val()).To(ContainSubstring(`serializedlength:4`))
err = client.Set("foo", "bar", 0).Err()
Expect(err).NotTo(HaveOccurred())
s, err := client.DebugObject("foo").Result()
Expect(err).NotTo(HaveOccurred())
Expect(s).To(ContainSubstring("serializedlength:4"))
})
It("should MemoryUsage", func() {
err := client.MemoryUsage("foo").Err()
Expect(err).To(Equal(redis.Nil))
err = client.Set("foo", "bar", 0).Err()
Expect(err).NotTo(HaveOccurred())
n, err := client.MemoryUsage("foo").Result()
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(int64(52)))
n, err = client.MemoryUsage("foo", 0).Result()
Expect(err).NotTo(HaveOccurred())
Expect(n).To(Equal(int64(52)))
})
})