I have redis Server with a few db, i want to connect to db1 in the server.
i manage to connect to the server but i couldn’t connect to one of the db.
this is my code:
package main
import (
"fmt"
"redigo-master"
)
func main() {
conn, err := redis.Dial("tcp", "qacd:6410")
defer conn.Close()
if err != nil {
fmt.Println(err)
}
keys, err := conn.Do("SELECT","db1")
fmt.Println(keys)
}
the result is:
ERR invalid DB index
any way to get to the 1st db?
2
Answers
As you can see in the SELECT command documentation:
which means that you’re supposed to pass an integer (in your case that would be 1), so it should look like this:
keys, err := conn.Do("SELECT","1")
In general Redis databases are assigned numbers starting from 0, and you have to configure in the redis.conf how many of them you want to have (by default you have 16 at indexes from 0 to 15):
Redis support 16 database. You can switch a DB using an integer starting from 0 to 15