mirror of https://github.com/go-redis/redis.git
Add MemoryUsage
This commit is contained in:
parent
7c9aa65a40
commit
ce9cfe9417
20
commands.go
20
commands.go
|
@ -62,6 +62,7 @@ type Cmdable interface {
|
||||||
TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)
|
TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)
|
||||||
TxPipeline() Pipeliner
|
TxPipeline() Pipeliner
|
||||||
|
|
||||||
|
Command() *CommandsInfoCmd
|
||||||
ClientGetName() *StringCmd
|
ClientGetName() *StringCmd
|
||||||
Echo(message interface{}) *StringCmd
|
Echo(message interface{}) *StringCmd
|
||||||
Ping() *StatusCmd
|
Ping() *StatusCmd
|
||||||
|
@ -275,9 +276,9 @@ type Cmdable interface {
|
||||||
GeoRadiusByMemberRO(key, member string, query *GeoRadiusQuery) *GeoLocationCmd
|
GeoRadiusByMemberRO(key, member string, query *GeoRadiusQuery) *GeoLocationCmd
|
||||||
GeoDist(key string, member1, member2, unit string) *FloatCmd
|
GeoDist(key string, member1, member2, unit string) *FloatCmd
|
||||||
GeoHash(key string, members ...string) *StringSliceCmd
|
GeoHash(key string, members ...string) *StringSliceCmd
|
||||||
Command() *CommandsInfoCmd
|
|
||||||
ReadOnly() *StatusCmd
|
ReadOnly() *StatusCmd
|
||||||
ReadWrite() *StatusCmd
|
ReadWrite() *StatusCmd
|
||||||
|
MemoryUsage(key string, samples ...int) *IntCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatefulCmdable interface {
|
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 {
|
func (c *cmdable) Del(keys ...string) *IntCmd {
|
||||||
args := make([]interface{}, 1+len(keys))
|
args := make([]interface{}, 1+len(keys))
|
||||||
args[0] = "del"
|
args[0] = "del"
|
||||||
|
@ -2301,8 +2308,15 @@ func (c *cmdable) GeoPos(key string, members ...string) *GeoPosCmd {
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
func (c *cmdable) Command() *CommandsInfoCmd {
|
func (c *cmdable) MemoryUsage(key string, samples ...int) *IntCmd {
|
||||||
cmd := NewCommandsInfoCmd("command")
|
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)
|
c.process(cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,14 +244,31 @@ var _ = Describe("Commands", func() {
|
||||||
Describe("debugging", func() {
|
Describe("debugging", func() {
|
||||||
|
|
||||||
It("should DebugObject", func() {
|
It("should DebugObject", func() {
|
||||||
debug := client.DebugObject("foo")
|
err := client.DebugObject("foo").Err()
|
||||||
Expect(debug.Err()).To(HaveOccurred())
|
Expect(err).To(MatchError("ERR no such key"))
|
||||||
Expect(debug.Err().Error()).To(Equal("ERR no such key"))
|
|
||||||
|
|
||||||
client.Set("foo", "bar", 0)
|
err = client.Set("foo", "bar", 0).Err()
|
||||||
debug = client.DebugObject("foo")
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(debug.Err()).NotTo(HaveOccurred())
|
|
||||||
Expect(debug.Val()).To(ContainSubstring(`serializedlength:4`))
|
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)))
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue