Skip to content

Instantly share code, notes, and snippets.

@defp
Created May 19, 2013 08:18
Show Gist options
  • Select an option

  • Save defp/5607060 to your computer and use it in GitHub Desktop.

Select an option

Save defp/5607060 to your computer and use it in GitHub Desktop.
redis golang
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