Created
December 4, 2014 09:40
-
-
Save zaiste/47edd23368f63f8bd1c0 to your computer and use it in GitHub Desktop.
Using Redis in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/garyburd/redigo/redis" | |
) | |
func main() { | |
c, err := redis.Dial("tcp", ":6379") | |
if err != nil { | |
panic(err) | |
} | |
defer c.Close() | |
c.Do("SET", "foo", "This is foo") | |
c.Do("HSET", "bar", "1", "First bar") | |
val1, err := redis.String(c.Do("GET", "foo")) | |
if err != nil { | |
fmt.Println("key not found") | |
} | |
fmt.Println(val1) | |
val2, err := redis.String(c.Do("HGET", "bar", "1")) | |
if err != nil { | |
fmt.Println("key not found") | |
} | |
fmt.Println(val2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment