command_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package redis_test
  2. import (
  3. "github.com/go-redis/redis"
  4. . "github.com/onsi/ginkgo"
  5. . "github.com/onsi/gomega"
  6. )
  7. var _ = Describe("Cmd", func() {
  8. var client *redis.Client
  9. BeforeEach(func() {
  10. client = redis.NewClient(redisOptions())
  11. Expect(client.FlushDB().Err()).NotTo(HaveOccurred())
  12. })
  13. AfterEach(func() {
  14. Expect(client.Close()).NotTo(HaveOccurred())
  15. })
  16. It("implements Stringer", func() {
  17. set := client.Set("foo", "bar", 0)
  18. Expect(set.String()).To(Equal("set foo bar: OK"))
  19. get := client.Get("foo")
  20. Expect(get.String()).To(Equal("get foo: bar"))
  21. })
  22. It("has val/err", func() {
  23. set := client.Set("key", "hello", 0)
  24. Expect(set.Err()).NotTo(HaveOccurred())
  25. Expect(set.Val()).To(Equal("OK"))
  26. get := client.Get("key")
  27. Expect(get.Err()).NotTo(HaveOccurred())
  28. Expect(get.Val()).To(Equal("hello"))
  29. Expect(set.Err()).NotTo(HaveOccurred())
  30. Expect(set.Val()).To(Equal("OK"))
  31. })
  32. It("has helpers", func() {
  33. set := client.Set("key", "10", 0)
  34. Expect(set.Err()).NotTo(HaveOccurred())
  35. n, err := client.Get("key").Int64()
  36. Expect(err).NotTo(HaveOccurred())
  37. Expect(n).To(Equal(int64(10)))
  38. un, err := client.Get("key").Uint64()
  39. Expect(err).NotTo(HaveOccurred())
  40. Expect(un).To(Equal(uint64(10)))
  41. f, err := client.Get("key").Float64()
  42. Expect(err).NotTo(HaveOccurred())
  43. Expect(f).To(Equal(float64(10)))
  44. })
  45. It("supports float32", func() {
  46. f := float32(66.97)
  47. err := client.Set("float_key", f, 0).Err()
  48. Expect(err).NotTo(HaveOccurred())
  49. val, err := client.Get("float_key").Float32()
  50. Expect(err).NotTo(HaveOccurred())
  51. Expect(val).To(Equal(f))
  52. })
  53. })