Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rueidis.Incomplete represents an incomplete Redis command #368

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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