Golang redisgo uses lua scripts to get hash values in batches

problem description

use the redisgo command: redis.NewScript (keyCount, LuaSrcript) .Do (conn, args.)

but what is returned is [] interface {} how to convert a two-dimensional array?

related codes

luaScript: = "local rst= {}; for I in pairs (KEYS) do rst v in pairs (KEYS) do rst [I] = redis.call ("hgetall", v) end; return rst"
redis.NewScript (2, LuaSrcript) .Do (conn, "user:1", "user:2")

Apr.02,2021

to convert a to interface I , you can do this a. (I) .

redis returns the relationship between value type and go type

Redis type              Go type
error                   redis.Error
integer                 int64
simple string           string
bulk string             []byte or nil if value not present.
array                   []interface{} or nil if value not present.

reference code

package main

import (
    "fmt"

    "github.com/gomodule/redigo/redis"
)

func main() {
    c, _ := redis.Dial("tcp", ":6379")
    var script = redis.NewScript(2, `
        local rst={};
        for i,v in pairs(KEYS) do
          rst[i]=redis.call('get', v)
        end;
        return rst`)
    reply, _ := script.Do(c, "key1", "key2")

    array := reply.([]interface{})
    for i, item := range array {
        if item != nil {
            //  key1key2  bulk string
            fmt.Println(i, string(item.([]byte)))
        }
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b385d9-2c110.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b385d9-2c110.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?