mirror of
https://github.com/redis/go-redis.git
synced 2025-04-17 20:17:02 +03:00
Add: Support for COMMAND LIST command (#2491)
* feat: add support and tests for Command list command Co-authored-by: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com>
This commit is contained in:
parent
30a6f7107e
commit
049d4f9691
@ -3992,3 +3992,10 @@ func (cmd *FunctionListCmd) readFunctions(rd *proto.Reader) ([]Function, error)
|
|||||||
}
|
}
|
||||||
return functions, nil
|
return functions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FilterBy struct {
|
||||||
|
Module string
|
||||||
|
ACLCat string
|
||||||
|
Pattern string
|
||||||
|
}
|
||||||
|
|
||||||
|
18
commands.go
18
commands.go
@ -124,6 +124,7 @@ type Cmdable interface {
|
|||||||
TxPipeline() Pipeliner
|
TxPipeline() Pipeliner
|
||||||
|
|
||||||
Command(ctx context.Context) *CommandsInfoCmd
|
Command(ctx context.Context) *CommandsInfoCmd
|
||||||
|
CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd
|
||||||
ClientGetName(ctx context.Context) *StringCmd
|
ClientGetName(ctx context.Context) *StringCmd
|
||||||
Echo(ctx context.Context, message interface{}) *StringCmd
|
Echo(ctx context.Context, message interface{}) *StringCmd
|
||||||
Ping(ctx context.Context) *StatusCmd
|
Ping(ctx context.Context) *StatusCmd
|
||||||
@ -537,6 +538,23 @@ func (c cmdable) Command(ctx context.Context) *CommandsInfoCmd {
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c cmdable) CommandList(ctx context.Context, filter *FilterBy) *StringSliceCmd {
|
||||||
|
args := make([]interface{}, 0, 5)
|
||||||
|
args = append(args, "command", "list")
|
||||||
|
if filter != nil {
|
||||||
|
if filter.Module != "" {
|
||||||
|
args = append(args, "filterby", "module", filter.Module)
|
||||||
|
} else if filter.ACLCat != "" {
|
||||||
|
args = append(args, "filterby", "aclcat", filter.ACLCat)
|
||||||
|
} else if filter.Pattern != "" {
|
||||||
|
args = append(args, "filterby", "pattern", filter.Pattern)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cmd := NewStringSliceCmd(ctx, args...)
|
||||||
|
_ = c(ctx, cmd)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
// ClientGetName returns the name of the connection.
|
// ClientGetName returns the name of the connection.
|
||||||
func (c cmdable) ClientGetName(ctx context.Context) *StringCmd {
|
func (c cmdable) ClientGetName(ctx context.Context) *StringCmd {
|
||||||
cmd := NewStringCmd(ctx, "client", "getname")
|
cmd := NewStringCmd(ctx, "client", "getname")
|
||||||
|
@ -6277,6 +6277,57 @@ var _ = Describe("Commands", func() {
|
|||||||
Expect(err).To(Equal(redis.Nil))
|
Expect(err).To(Equal(redis.Nil))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should return all command names", func() {
|
||||||
|
cmdList := client.CommandList(ctx, nil)
|
||||||
|
Expect(cmdList.Err()).NotTo(HaveOccurred())
|
||||||
|
cmdNames := cmdList.Val()
|
||||||
|
|
||||||
|
Expect(cmdNames).NotTo(BeEmpty())
|
||||||
|
|
||||||
|
// Assert that some expected commands are present in the list
|
||||||
|
Expect(cmdNames).To(ContainElement("get"))
|
||||||
|
Expect(cmdNames).To(ContainElement("set"))
|
||||||
|
Expect(cmdNames).To(ContainElement("hset"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should filter commands by module", func() {
|
||||||
|
filter := &redis.FilterBy{
|
||||||
|
Module: "JSON",
|
||||||
|
}
|
||||||
|
cmdList := client.CommandList(ctx, filter)
|
||||||
|
Expect(cmdList.Err()).NotTo(HaveOccurred())
|
||||||
|
Expect(cmdList.Val()).To(HaveLen(0))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should filter commands by ACL category", func() {
|
||||||
|
|
||||||
|
filter := &redis.FilterBy{
|
||||||
|
ACLCat: "admin",
|
||||||
|
}
|
||||||
|
|
||||||
|
cmdList := client.CommandList(ctx, filter)
|
||||||
|
Expect(cmdList.Err()).NotTo(HaveOccurred())
|
||||||
|
cmdNames := cmdList.Val()
|
||||||
|
|
||||||
|
// Assert that the returned list only contains commands from the admin ACL category
|
||||||
|
Expect(len(cmdNames)).To(BeNumerically(">", 10))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should filter commands by pattern", func() {
|
||||||
|
filter := &redis.FilterBy{
|
||||||
|
Pattern: "*GET*",
|
||||||
|
}
|
||||||
|
cmdList := client.CommandList(ctx, filter)
|
||||||
|
Expect(cmdList.Err()).NotTo(HaveOccurred())
|
||||||
|
cmdNames := cmdList.Val()
|
||||||
|
|
||||||
|
// Assert that the returned list only contains commands that match the given pattern
|
||||||
|
Expect(cmdNames).To(ContainElement("get"))
|
||||||
|
Expect(cmdNames).To(ContainElement("getbit"))
|
||||||
|
Expect(cmdNames).To(ContainElement("getrange"))
|
||||||
|
Expect(cmdNames).NotTo(ContainElement("set"))
|
||||||
|
})
|
||||||
|
|
||||||
It("Dump and restores all libraries", func() {
|
It("Dump and restores all libraries", func() {
|
||||||
err := client.FunctionLoad(ctx, lib1Code).Err()
|
err := client.FunctionLoad(ctx, lib1Code).Err()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user