redigo ZRANGE: ERR syntax error

884 views
Skip to first unread message

Johann Höchtl

unread,
Jun 30, 2013, 11:36:54 AM6/30/13
to golan...@googlegroups.com
I try to get the result of a ZRANGE (or ZREVRANGE) with an optional WITHSCORES, however all I get is a ERR syntax error.

I guess I am doing sthg wrong while passing values to redis.Do(...) but I don't know


        sortorder := request.QueryParameter("sortorder")
        numds := request.QueryParameter("numds")

        var entity, command, redisparam string
        nums := -1
        returnnums := false

        if sortorder == "asc" {
            command = "ZRANGE"
        } else {
            command = "ZREVRANGE"
        }

        if len(numds) > 0 {
            var err error
            returnnums, err = strconv.ParseBool(numds)
            if err != nil {
                returnnums = false
            }
        }

        if returnnums {
            redisparam = "WITHSCORES"
        }

        reply, err := redis.Values(an.rcon.Do(command, "entities", "0", "-1", redisparam))
        if err != nil {
            panic(err)  // HERE I GET THE ERR syntax error
        }
       
        resultset := make([]UnitDSNums,0)

        for len(reply) > 0 {
            a := UnitDSNums{}
            if returnnums {
                reply, err = redis.Scan(reply, &entity, &nums)
                a.Numsets = nums
            } else {
                reply, err = redis.Scan(reply, &entity)
               
            }
            a.Entity = entity
            if err != nil {
                panic(err)
            }
            resultset = append(resultset, a)
        }

Johann Höchtl

unread,
Jun 30, 2013, 12:09:13 PM6/30/13
to golan...@googlegroups.com


Am Sonntag, 30. Juni 2013 17:36:54 UTC+2 schrieb Johann Höchtl:
I try to get the result of a ZRANGE (or ZREVRANGE) with an optional WITHSCORES, however all I get is a ERR syntax error.

I guess I am doing sthg wrong while passing values to redis.Do(...) but I don't know


        sortorder := request.QueryParameter("sortorder")
        numds := request.QueryParameter("numds")

        var entity, command, redisparam string
        nums := -1
        returnnums := false

        if sortorder == "asc" {
            command = "ZRANGE"
        } else {
            command = "ZREVRANGE"
        }

        if len(numds) > 0 {
            var err error
            returnnums, err = strconv.ParseBool(numds)
            if err != nil {
                returnnums = false
            }
        }

        if returnnums {
            redisparam = "WITHSCORES"
        }

        reply, err := redis.Values(an.rcon.Do(command, "entities", "0", "-1", redisparam))
 
Ok ,easy fix, redis.Do( .... does not accept an empty arguments for ZRANGE or ZREVRANGE

Reply all
Reply to author
Forward
0 new messages