redigo,SMEMBERS,如何获取字符串

我是redigo,要从Go连接到redis数据库。如何将类型转换[]interface {}{[]byte{} []byte{}}为一组字符串?在这种情况下,我想得到两个字符串HelloWorld


package main


import (

    "fmt"

    "github.com/garyburd/redigo/redis"

)


func main() {

    c, err := redis.Dial("tcp", ":6379")

    defer c.Close()

    if err != nil {

        fmt.Println(err)

    }

    c.Send("SADD", "myset", "Hello")

    c.Send("SADD", "myset", "World")

    c.Flush()

    c.Receive()

    c.Receive()


    err = c.Send("SMEMBERS", "myset")

    if err != nil {

        fmt.Println(err)

    }

    c.Flush()

    // both give the same return value!?!?

    // reply, err := c.Receive()

    reply, err := redis.MultiBulk(c.Receive())

    if err != nil {

        fmt.Println(err)

    }

    fmt.Printf("%#v\n", reply)

    // $ go run main.go

    // []interface {}{[]byte{0x57, 0x6f, 0x72, 0x6c, 0x64}, []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f}}

    // How do I get 'Hello' and 'World' from this data?

}


蓝山帝景
浏览 228回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go