Skip to content

Commit

Permalink
Merge pull request IBM-Cloud#5 from IBM-Cloud/evalextra
Browse files Browse the repository at this point in the history
First support for basic --eval as per redis-cli
  • Loading branch information
codepope committed Oct 3, 2018
2 parents 99ac2be + e10ccd8 commit edc1fe8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions redli.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
rediscertfile = kingpin.Flag("certfile", "Self-signed certificate file for validation").Envar("REDIS_CERTFILE").File()
rediscertb64 = kingpin.Flag("certb64", "Self-signed certificate string as base64 for validation").Envar("REDIS_CERTB64").String()
forceraw = kingpin.Flag("raw", "Produce raw output").Bool()
eval = kingpin.Flag("eval", "Evaluate a script").File()
commandargs = kingpin.Arg("commands", "Redis commands and values").Strings()
)

Expand Down Expand Up @@ -114,6 +115,49 @@ func main() {
}

// We may not need to carry on setting up the interactive front end so...
if *eval != nil {
command := *commandargs

scriptsrc, err := ioutil.ReadAll(*eval)

if err != nil {
log.Fatal(err)
}

var args = make([]interface{}, len(command[1:]))

keycnt := 0
gotcomma := false

for i, d := range command {
if !gotcomma {
if d == "," {
gotcomma = true
} else {
args[i] = d
keycnt = keycnt + 1
}
} else {
args[i-1] = d
}
}

var iargs []interface{}
iargs = append(iargs, keycnt)
iargs = append(iargs, args...)

script := redis.NewScript(-1, string(scriptsrc[:]))
result, err := script.Do(conn, iargs)

if err != nil {
log.Fatal(err)
}

printRedisResult(result, false)

os.Exit(0)
}

if *commandargs != nil {
command := *commandargs
var args = make([]interface{}, len(command[1:]))
Expand Down

0 comments on commit edc1fe8

Please sign in to comment.