Fix lua scripts

This commit is contained in:
tidwall 2018-11-10 12:35:25 -07:00
parent f0209c8aad
commit 74a47309ec
1 changed files with 69 additions and 66 deletions

View File

@ -544,29 +544,30 @@ func main() {
)
}
case "EVAL":
if !redis {
if redis {
break
}
var i int64
get_script := "return tile38.call('GET', KEYS[1], ARGV[1], 'point')"
get4_script :=
"a = tile38.call('GET', KEYS[1], ARGV[1], 'point');" +
"b = tile38.call('GET', KEYS[1], ARGV[2], 'point');" +
"c = tile38.call('GET', KEYS[1], ARGV[3], 'point');" +
"d = tile38.call('GET', KEYS[1], ARGV[4], 'point');" +
getScript := "return tile38.call('GET', KEYS[1], ARGV[1], 'point')"
get4Script :=
"local a = tile38.call('GET', KEYS[1], ARGV[1], 'point');" +
"local b = tile38.call('GET', KEYS[1], ARGV[2], 'point');" +
"local c = tile38.call('GET', KEYS[1], ARGV[3], 'point');" +
"local d = tile38.call('GET', KEYS[1], ARGV[4], 'point');" +
"return d"
set_script := "return tile38.call('SET', KEYS[1], ARGV[1], 'point', ARGV[2], ARGV[3])"
setScript := "return tile38.call('SET', KEYS[1], ARGV[1], 'point', ARGV[2], ARGV[3])"
if !opts.Quiet {
fmt.Println("Scripts to run:")
fmt.Println("GET SCRIPT: " + get_script)
fmt.Println("GET FOUR SCRIPT: " + get4_script)
fmt.Println("SET SCRIPT: " + set_script)
fmt.Println("GET SCRIPT: " + getScript)
fmt.Println("GET FOUR SCRIPT: " + get4Script)
fmt.Println("SET SCRIPT: " + setScript)
}
redbench.Bench("EVAL (set point)", addr, opts, prepFn,
func(buf []byte) []byte {
i := atomic.AddInt64(&i, 1)
lat, lon := randPoint()
return redbench.AppendCommand(buf, "EVAL", set_script, "1",
return redbench.AppendCommand(buf, "EVAL", setScript, "1",
"key:bench",
"id:"+strconv.FormatInt(i, 10),
strconv.FormatFloat(lat, 'f', 5, 64),
@ -578,7 +579,7 @@ func main() {
func(buf []byte) []byte {
i := atomic.AddInt64(&i, 1)
lat, lon := randPoint()
return redbench.AppendCommand(buf, "EVALNA", set_script, "1",
return redbench.AppendCommand(buf, "EVALNA", setScript, "1",
"key:bench",
"id:"+strconv.FormatInt(i, 10),
strconv.FormatFloat(lat, 'f', 5, 64),
@ -589,31 +590,33 @@ func main() {
redbench.Bench("EVALRO (get point)", addr, opts, prepFn,
func(buf []byte) []byte {
i := atomic.AddInt64(&i, 1)
return redbench.AppendCommand(buf, "EVALRO", get_script, "1", "key:bench", "id:"+strconv.FormatInt(i, 10))
args := []string{"EVALRO", getScript, "1", "key:bench", "id:" + strconv.FormatInt(i, 10)}
return redbench.AppendCommand(buf, args...)
},
)
redbench.Bench("EVALRO (get 4 points)", addr, opts, prepFn,
func(buf []byte) []byte {
i := atomic.AddInt64(&i, 1)
return redbench.AppendCommand(buf, "EVALRO", get4_script, "1",
args := []string{
"EVALRO", get4Script, "1",
"key:bench",
"id:" + strconv.FormatInt(i, 10),
"id:" + strconv.FormatInt(i+1, 10),
"id:" + strconv.FormatInt(i+2, 10),
"id:" + strconv.FormatInt(i+3, 10),
)
}
return redbench.AppendCommand(buf, args...)
},
)
redbench.Bench("EVALNA (get point)", addr, opts, prepFn,
func(buf []byte) []byte {
i := atomic.AddInt64(&i, 1)
return redbench.AppendCommand(buf, "EVALNA", get_script, "1", "key:bench", "id:"+strconv.FormatInt(i, 10))
return redbench.AppendCommand(buf, "EVALNA", getScript, "1", "key:bench", "id:"+strconv.FormatInt(i, 10))
},
)
}
}
}
}
const earthRadius = 6371e3