Skip to content

Commit

Permalink
command: select, flushall (#32)
Browse files Browse the repository at this point in the history
The Redis WordPress plugin (wp-redis) uses SELECT to connect to a database.
Older versions of this plugin (<0.8.0) also use FLUSHALL instead of FLUSHDB
to flush the cache.

See https://github.com/pantheon-systems/wp-redis
  • Loading branch information
ydf authored Aug 9, 2024
1 parent 6ceaa64 commit 3037996
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func Parse(args [][]byte) (redis.Cmd, error) {
return server.ParseDBSize(b)
case "flushdb":
return key.ParseFlushDB(b)
case "flushall":
return key.ParseFlushDB(b)
case "info":
return server.ParseOK(b)
case "lolwut":
Expand All @@ -38,6 +40,8 @@ func Parse(args [][]byte) (redis.Cmd, error) {
return conn.ParseEcho(b)
case "ping":
return conn.ParsePing(b)
case "select":
return conn.ParseSelect(b)

// key
case "del":
Expand Down
33 changes: 33 additions & 0 deletions internal/command/conn/select.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package conn

import (
"github.com/nalgeon/redka/internal/parser"
"github.com/nalgeon/redka/internal/redis"
)

const (
RESPONSE = "OK"
)

// Returns the server's liveliness response.
// https://redis.io/commands/select
type Select struct {
redis.BaseCmd
index int
}

func ParseSelect(b redis.BaseCmd) (Select, error) {
cmd := Select{BaseCmd: b}
err := parser.New(
parser.Int(&cmd.index),
).Required(1).Run(cmd.Args())
if err != nil {
return Select{}, err
}
return cmd, nil
}

func (c Select) Run(w redis.Writer, _ redis.Redka) (any, error) {
w.WriteBulkString(RESPONSE)
return RESPONSE, nil
}

0 comments on commit 3037996

Please sign in to comment.