Skip to content

Commit

Permalink
feat: rueidis.Incomplete represents an incomplete Redis command
Browse files Browse the repository at this point in the history
  • Loading branch information
rueian committed Sep 12, 2023
1 parent 73da7f7 commit 2815c44
Show file tree
Hide file tree
Showing 36 changed files with 3,540 additions and 3,530 deletions.
3 changes: 3 additions & 0 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import "github.com/redis/rueidis/internal/cmds"
// Builder represents a command builder. It should only be created from the client.B() method.
type Builder = cmds.Builder

// Incomplete represents an incomplete Redis command. It should then be completed by calling the Build().
type Incomplete = cmds.Incomplete

// Completed represents a completed Redis command. It should only be created from the Build() of a command builder.
type Completed = cmds.Completed

Expand Down
8 changes: 4 additions & 4 deletions hack/cmds/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func generate(f io.Writer, structs map[string]goStruct) {
for _, name := range names {
s := structs[name]

fmt.Fprintf(f, "type %s Completed\n\n", s.FullName)
fmt.Fprintf(f, "type %s Incomplete\n\n", s.FullName)

if s.Node.Root {
printRootBuilder(f, s)
Expand Down Expand Up @@ -666,7 +666,7 @@ func printRootBuilder(w io.Writer, root goStruct) {
}

if tag := rootCf(root); tag != "" {
fmt.Fprintf(w, "\tc = %s{cs: get(), ks: b.ks, cf: %s}\n", root.FullName, tag)
fmt.Fprintf(w, "\tc = %s{cs: get(), ks: b.ks, cf: int16(%s)}\n", root.FullName, tag)
} else {
fmt.Fprintf(w, "\tc = %s{cs: get(), ks: b.ks}\n", root.FullName)
}
Expand Down Expand Up @@ -714,7 +714,7 @@ func rootCf(root goStruct) (tag string) {
func printFinalBuilder(w io.Writer, parent goStruct, method, ss string) {
fmt.Fprintf(w, "func (c %s) %s() %s {\n", parent.FullName, method, ss)
fmt.Fprintf(w, "\tc.cs.Build()\n")
fmt.Fprintf(w, "\treturn %s(c)\n", ss)
fmt.Fprintf(w, "\treturn %s{cs: c.cs, cf: uint16(c.cf), ks: c.ks}\n", ss)
fmt.Fprintf(w, "}\n\n")
}

Expand Down Expand Up @@ -766,7 +766,7 @@ func printBuilder(w io.Writer, parent, next goStruct) {

for _, cmd := range next.BuildDef.Command {
if cmd == "BLOCK" {
fmt.Fprintf(w, "\tc.cf = blockTag\n")
fmt.Fprintf(w, "\tc.cf = int16(blockTag)\n")
break
}
}
Expand Down
7 changes: 7 additions & 0 deletions internal/cmds/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ func ToBlock(c *Completed) {
c.cf |= blockTag
}

// Incomplete represents an incomplete Redis command. It should then be completed by calling the Build().
type Incomplete struct {
cs *CommandSlice
cf int16 // use int16 instead of uint16 to make a difference with Completed
ks uint16
}

// Completed represents a completed Redis command, should be created by the Build() of command builder.
type Completed struct {
cs *CommandSlice
Expand Down
Loading

0 comments on commit 2815c44

Please sign in to comment.