reply_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2012 Gary Burd
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"): you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. // License for the specific language governing permissions and limitations
  13. // under the License.
  14. package redis_test
  15. import (
  16. "fmt"
  17. "github.com/garyburd/redigo/redis"
  18. )
  19. func ExampleBool() {
  20. c, err := dial()
  21. if err != nil {
  22. panic(err)
  23. }
  24. defer c.Close()
  25. c.Do("SET", "foo", 1)
  26. exists, _ := redis.Bool(c.Do("EXISTS", "foo"))
  27. fmt.Printf("%#v\n", exists)
  28. // Output:
  29. // true
  30. }
  31. func ExampleInt() {
  32. c, err := dial()
  33. if err != nil {
  34. panic(err)
  35. }
  36. defer c.Close()
  37. c.Do("SET", "k1", 1)
  38. n, _ := redis.Int(c.Do("GET", "k1"))
  39. fmt.Printf("%#v\n", n)
  40. n, _ = redis.Int(c.Do("INCR", "k1"))
  41. fmt.Printf("%#v\n", n)
  42. // Output:
  43. // 1
  44. // 2
  45. }
  46. func ExampleString() {
  47. c, err := dial()
  48. if err != nil {
  49. panic(err)
  50. }
  51. defer c.Close()
  52. c.Do("SET", "hello", "world")
  53. s, err := redis.String(c.Do("GET", "hello"))
  54. fmt.Printf("%#v\n", s)
  55. // Output:
  56. // "world"
  57. }