1. String批量操作

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/garyburd/redigo/redis"
  5. )
  6. func main() {
  7. c, err := redis.Dial("tcp", "localhost:6379")
  8. if err != nil {
  9. fmt.Println("conn redis failed,", err)
  10. return
  11. }
  12. defer c.Close()
  13. _, err = c.Do("MSet", "abc", 100, "efg", 300)
  14. if err != nil {
  15. fmt.Println(err)
  16. return
  17. }
  18. r, err := redis.Ints(c.Do("MGet", "abc", "efg"))
  19. if err != nil {
  20. fmt.Println("get abc failed,", err)
  21. return
  22. }
  23. for _, v := range r {
  24. fmt.Println(v)
  25. }
  26. }

运行结果:

  1. 100
  2. 300

redis窗口:

  1. 127.0.0.1:6379> mget abc efg
  2. 1) "100"
  3. 2) "300"