Created
May 19, 2013 08:18
-
-
Save defp/5607060 to your computer and use it in GitHub Desktop.
redis golang
This file contains hidden or 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/hoisie/redis" | |
| "strconv" | |
| "strings" | |
| ) | |
| func main() { | |
| var client redis.Client | |
| ids, _ := client.Smembers("room:abc:users") | |
| fmt.Println(ids) | |
| for _, id := range ids { | |
| a := string(id[0]) | |
| fmt.Println(a) | |
| userkey := "user:" + a | |
| user := make(map[string]string) | |
| err := client.Hgetall(userkey, user) | |
| if err == nil { | |
| } | |
| fmt.Println(user["name"]) | |
| fmt.Println(strconv.Atoi(user["id"])) | |
| } | |
| messages, _ := client.Lrange("room:abc", 0, 10) | |
| //for _, m := range messages { | |
| // mm := string(m) | |
| // fmt.Println(mm) | |
| //} | |
| if len(messages) == 0 { | |
| return | |
| } | |
| m := string(messages[0]) | |
| fmt.Println(m) | |
| mm := strings.Split(m, "|") | |
| fmt.Println(mm[3]) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment