package main import ( "time" "github.com/garyburd/redigo/redis" ) func main() { conn, err := redis.Dial("tcp", "localhost:6379") if err != nil { panic(err) } // defer the closing of the connection defer conn.Close() // do some Redis operations conn.Do("SET", "key", "value") conn.Do("EXPIRE", "key", 10*time.Second) // application continues to run time.Sleep(20 * time.Second) }
package main import ( "fmt" "github.com/garyburd/redigo/redis" ) func main() { conn, err := redis.Dial("tcp", "localhost:6379") if err != nil { panic(err) } // close the connection manually conn.Close() // do some Redis operations (this will cause an error) _, err = conn.Do("GET", "key") if err != nil { fmt.Println(err) } }In this example, a Redis connection is created using the Dial function. The connection is closed manually using the Close() method. Attempting to perform a Redis operation after the connection has been closed will result in an error. The error is printed to the console for demonstration purposes.