1. List队列操作

  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("lpush", "book_list", "abc", "ceg", 300)
  14. if err != nil {
  15. fmt.Println(err)
  16. return
  17. }
  18. r, err := redis.String(c.Do("lpop", "book_list"))
  19. if err != nil {
  20. fmt.Println("get abc failed,", err)
  21. return
  22. }
  23. fmt.Println(r)
  24. }

运行结果:

  1. 300

Redis命令行:

  1. 127.0.0.1:6379> lpop book_list
  2. "ceg"
  3. 127.0.0.1:6379> lpop book_list
  4. "abc"
  5. 127.0.0.1:6379> lpop book_list
  6. (nil)