将Redigo管道结果转换为字符串

将Redigo管道结果转换为字符串,go,redis,pipeline,Go,Redis,Pipeline,我设法将多个HGETALL命令通过管道传输,但无法将它们转换为字符串 我的示例代码如下: // Initialize Redis (Redigo) client on port 6379 // and default address 127.0.0.1/localhost client, err := redis.Dial("tcp", ":6379") if err != nil { panic(err) } defer client.Close() // Initialize

我设法将多个HGETALL命令通过管道传输,但无法将它们转换为字符串

我的示例代码如下:

// Initialize Redis (Redigo) client on port 6379 
//  and default address 127.0.0.1/localhost
client, err := redis.Dial("tcp", ":6379")
  if err != nil {
  panic(err)
}
defer client.Close()

// Initialize Pipeline
client.Send("MULTI")

// Send writes the command to the connection's output buffer
client.Send("HGETALL", "post:1") // Where "post:1" contains " title 'hi' "

client.Send("HGETALL", "post:2") // Where "post:1" contains " title 'hello' "

// Execute the Pipeline
pipe_prox, err := client.Do("EXEC")

if err != nil {
  panic(err)
}

log.Println(pipe_prox)
只要您能够轻松地显示非字符串结果,就可以了。。我得到的是:

[[[116 105 116 108 101] [104 105]] [[116 105 116 108 101] [104 101 108 108 111]]]
但我需要的是:

"title" "hi" "title" "hello"
我还尝试了以下组合和其他组合:

result, _ := redis.Strings(pipe_prox, err)

log.Println(pipe_prox)
但我得到的只是:
[]

我应该注意,它可以与多个HGET键值命令一起工作,但这不是我所需要的

我做错了什么?如何将“数字映射”转换为字符串


感谢您的帮助

每个
HGETALL
都返回自己的一系列值,这些值需要转换为字符串,管道将返回一系列值。首先使用通用的
redis.Values
分解这个外部结构,然后可以解析内部切片

// Execute the Pipeline
pipe_prox, err := redis.Values(client.Do("EXEC"))

if err != nil {
    panic(err)
}

for _, v := range pipe_prox {
    s, err := redis.Strings(v, nil)
    if err != nil {
        fmt.Println("Not a bulk strings repsonse", err)
    }

    fmt.Println(s)
}
印刷品:

[title hi]
[title hello]

每个
HGETALL
都返回自己的一系列值,这些值需要转换为字符串,管道将返回一系列值。首先使用通用的
redis.Values
分解这个外部结构,然后可以解析内部切片

// Execute the Pipeline
pipe_prox, err := redis.Values(client.Do("EXEC"))

if err != nil {
    panic(err)
}

for _, v := range pipe_prox {
    s, err := redis.Strings(v, nil)
    if err != nil {
        fmt.Println("Not a bulk strings repsonse", err)
    }

    fmt.Println(s)
}
印刷品:

[title hi]
[title hello]

您可以这样做:

pipe_prox, err := redis.Values(client.Do("EXEC"))
for _, v := range pipe_prox.([]interface{}) {
    fmt.Println(v)
}

您可以这样做:

pipe_prox, err := redis.Values(client.Do("EXEC"))
for _, v := range pipe_prox.([]interface{}) {
    fmt.Println(v)
}