mirror of
https://github.com/redis/go-redis.git
synced 2025-04-19 07:22:17 +03:00
Cleanup
This commit is contained in:
parent
be9ae84c6f
commit
dfae0ec28b
31
command.go
31
command.go
@ -2172,15 +2172,13 @@ func (c *cmdsInfoCache) Get() (map[string]*CommandInfo, error) {
|
|||||||
|
|
||||||
type SlowLog struct {
|
type SlowLog struct {
|
||||||
ID int64
|
ID int64
|
||||||
CreatedAt time.Time
|
Time time.Time
|
||||||
Costs time.Duration
|
Duration time.Duration
|
||||||
/*
|
|
||||||
ClientAddress,ClientName
|
|
||||||
There are also optional fields emitted only by Redis 4.0 or greater:
|
|
||||||
https://redis.io/commands/slowlog#output-format
|
|
||||||
*/
|
|
||||||
ClientAddress, ClientName string
|
|
||||||
Args []string
|
Args []string
|
||||||
|
// These are also optional fields emitted only by Redis 4.0 or greater:
|
||||||
|
// https://redis.io/commands/slowlog#output-format
|
||||||
|
ClientAddr string
|
||||||
|
ClientName string
|
||||||
}
|
}
|
||||||
|
|
||||||
type SlowLogCmd struct {
|
type SlowLogCmd struct {
|
||||||
@ -2235,19 +2233,22 @@ func (cmd *SlowLogCmd) readReply(rd *proto.Reader) error {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
createdAtTime := time.Unix(createdAt, 0)
|
createdAtTime := time.Unix(createdAt, 0)
|
||||||
|
|
||||||
costs, err := rd.ReadIntReply()
|
costs, err := rd.ReadIntReply()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
costsDuration := time.Duration(costs) * time.Microsecond
|
costsDuration := time.Duration(costs) * time.Microsecond
|
||||||
|
|
||||||
cmdLen, err := rd.ReadArrayLen()
|
cmdLen, err := rd.ReadArrayLen()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if cmdLen < 1 {
|
if cmdLen < 1 {
|
||||||
err := fmt.Errorf("redis: got %d elements commands reply in slowlog get, expected at least 1", cmdLen)
|
err := fmt.Errorf("redis: got %d elements commands reply in slowlog get, expected at least 1", cmdLen)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
cmdString := make([]string, cmdLen)
|
cmdString := make([]string, cmdLen)
|
||||||
for i := 0; i < int(cmdLen); i++ {
|
for i := 0; i < int(cmdLen); i++ {
|
||||||
cmdString[i], err = rd.ReadString()
|
cmdString[i], err = rd.ReadString()
|
||||||
@ -2255,6 +2256,7 @@ func (cmd *SlowLogCmd) readReply(rd *proto.Reader) error {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var address, name string
|
var address, name string
|
||||||
for i := 4; i < int(n); i++ {
|
for i := 4; i < int(n); i++ {
|
||||||
str, err := rd.ReadString()
|
str, err := rd.ReadString()
|
||||||
@ -2267,12 +2269,13 @@ func (cmd *SlowLogCmd) readReply(rd *proto.Reader) error {
|
|||||||
name = str
|
name = str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.val[i] = SlowLog{
|
cmd.val[i] = SlowLog{
|
||||||
ID: id,
|
ID: id,
|
||||||
CreatedAt: createdAtTime,
|
Time: createdAtTime,
|
||||||
Costs: costsDuration,
|
Duration: costsDuration,
|
||||||
Args: cmdString,
|
Args: cmdString,
|
||||||
ClientAddress: address,
|
ClientAddr: address,
|
||||||
ClientName: name,
|
ClientName: name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4016,19 +4016,20 @@ var _ = Describe("Commands", func() {
|
|||||||
|
|
||||||
Describe("SlowLog", func() {
|
Describe("SlowLog", func() {
|
||||||
It("returns slow query result", func() {
|
It("returns slow query result", func() {
|
||||||
var CONFIGSLOWKEY string = "slowlog-log-slower-than"
|
const key = "slowlog-log-slower-than"
|
||||||
old := client.ConfigGet(ctx, CONFIGSLOWKEY).Val()
|
|
||||||
client.ConfigSet(ctx, CONFIGSLOWKEY, "0")
|
old := client.ConfigGet(ctx, key).Val()
|
||||||
defer client.ConfigSet(ctx, CONFIGSLOWKEY, old[1].(string))
|
client.ConfigSet(ctx, key, "0")
|
||||||
_, e := client.Eval(ctx, "redis.call('slowlog','reset')", []string{}).Result()
|
defer client.ConfigSet(ctx, key, old[1].(string))
|
||||||
if e != nil && e != redis.Nil {
|
|
||||||
fmt.Println(e)
|
err := rdb.Do(ctx, "slowlog", "reset").Err()
|
||||||
return
|
Expect(err).NotTo(HaveOccurred())
|
||||||
}
|
|
||||||
client.Set(ctx, "test", "true", 0)
|
client.Set(ctx, "test", "true", 0)
|
||||||
|
|
||||||
result, err := client.SlowLog(ctx, -1).Result()
|
result, err := client.SlowLog(ctx, -1).Result()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(result)).To(Equal(3))
|
Expect(len(result)).To(Equal(2))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -512,19 +512,22 @@ func ExampleNewUniversalClient_cluster() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExampleClient_SlowLog() {
|
func ExampleClient_SlowLog() {
|
||||||
var (
|
const key = "slowlog-log-slower-than"
|
||||||
CONFIGSLOWKEY string = "slowlog-log-slower-than"
|
|
||||||
)
|
old := rdb.ConfigGet(ctx, key).Val()
|
||||||
old := rdb.ConfigGet(ctx, CONFIGSLOWKEY).Val()
|
rdb.ConfigSet(ctx, key, "0")
|
||||||
rdb.ConfigSet(ctx, CONFIGSLOWKEY, "0")
|
defer rdb.ConfigSet(ctx, key, old[1].(string))
|
||||||
defer rdb.ConfigSet(ctx, CONFIGSLOWKEY, old[1].(string))
|
|
||||||
_, e := rdb.Eval(ctx, "redis.call('slowlog','reset')", []string{}).Result()
|
if err := rdb.Do(ctx, "slowlog", "reset").Err(); err != nil {
|
||||||
if e != nil && e != redis.Nil {
|
panic(err)
|
||||||
fmt.Println(e)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rdb.Set(ctx, "test", "true", 0)
|
rdb.Set(ctx, "test", "true", 0)
|
||||||
|
|
||||||
result, err := rdb.SlowLog(ctx, -1).Result()
|
result, err := rdb.SlowLog(ctx, -1).Result()
|
||||||
fmt.Println(len(result), err)
|
if err != nil {
|
||||||
// Output: 3 <nil>
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println(len(result))
|
||||||
|
// Output: 2
|
||||||
}
|
}
|
||||||
|
1
go.sum
1
go.sum
@ -43,6 +43,7 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k
|
|||||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||||
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
||||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||||
|
github.com/onsi/gomega v1.10.2 h1:aY/nuoWlKJud2J6U0E3NWsjlg+0GtwXxgEqthRdzlcs=
|
||||||
github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user