Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从redis服务器获取列表元素,从[]接口{}到[]字符串_Redis_Go_Types - Fatal编程技术网

从redis服务器获取列表元素,从[]接口{}到[]字符串

从redis服务器获取列表元素,从[]接口{}到[]字符串,redis,go,types,Redis,Go,Types,我正在尝试使用连接,redis server正在运行 我想创建一组字符串,附加一个字符串,然后从服务器获取所有元素并打印出来 这个,我试过的 package main import ( "fmt" "github.com/garyburd/redigo/redis" ) func main() { c, err := redis.Dial("tcp", ":6379") check(err) defer c.Close() _, err = c

我正在尝试使用连接,
redis server
正在运行

我想创建一组字符串,附加一个字符串,然后从服务器获取所有元素并打印出来

这个,我试过的

package main

import (
    "fmt"
    "github.com/garyburd/redigo/redis"
)

func main() {
    c, err := redis.Dial("tcp", ":6379")
    check(err)
    defer c.Close()
    _, err = c.Do("LPUSH", "bars", "foo")
    check(err)

    n, err := redis.Values(c.Do("LRANGE", "bars", 0, 10))
    check(err)
    fmt.Println(n)
}

func check(err error) {
    if err != nil {
        panic(err)
    }
}
我把
[[102 111]]
打印出来,而不是
foo
,看起来


如何将
[]接口{}
(返回类型)转换为
[]字符串

我不熟悉您正在使用的软件包,但建议使用
redis.Strings()
而不是
redis.Values()
来完成您想要的工作:

Strings是将多批量命令回复转换为[]字符串的帮助程序。如果err不等于nil,则字符串返回nil,err。如果多个批量项目不是批量值或nil,则字符串返回错误


也许您可以尝试一下golang的redis客户端:


:)

正是我所需要的。虽然这可以从理论上回答这个问题,但请在此处包含答案的基本部分,并提供链接以供参考。