redis 3.3.5 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +132 -2
  3. data/README.md +144 -79
  4. data/lib/redis.rb +1174 -405
  5. data/lib/redis/client.rb +150 -90
  6. data/lib/redis/cluster.rb +295 -0
  7. data/lib/redis/cluster/command.rb +81 -0
  8. data/lib/redis/cluster/command_loader.rb +34 -0
  9. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  10. data/lib/redis/cluster/node.rb +107 -0
  11. data/lib/redis/cluster/node_key.rb +31 -0
  12. data/lib/redis/cluster/node_loader.rb +37 -0
  13. data/lib/redis/cluster/option.rb +93 -0
  14. data/lib/redis/cluster/slot.rb +86 -0
  15. data/lib/redis/cluster/slot_loader.rb +49 -0
  16. data/lib/redis/connection.rb +4 -2
  17. data/lib/redis/connection/command_helper.rb +5 -10
  18. data/lib/redis/connection/hiredis.rb +6 -5
  19. data/lib/redis/connection/registry.rb +2 -1
  20. data/lib/redis/connection/ruby.rb +126 -128
  21. data/lib/redis/connection/synchrony.rb +21 -8
  22. data/lib/redis/distributed.rb +147 -72
  23. data/lib/redis/errors.rb +48 -0
  24. data/lib/redis/hash_ring.rb +30 -73
  25. data/lib/redis/pipeline.rb +55 -15
  26. data/lib/redis/subscribe.rb +11 -12
  27. data/lib/redis/version.rb +3 -1
  28. metadata +49 -202
  29. data/.gitignore +0 -16
  30. data/.travis.yml +0 -89
  31. data/.travis/Gemfile +0 -11
  32. data/.yardopts +0 -3
  33. data/Gemfile +0 -4
  34. data/Rakefile +0 -87
  35. data/benchmarking/logging.rb +0 -71
  36. data/benchmarking/pipeline.rb +0 -51
  37. data/benchmarking/speed.rb +0 -21
  38. data/benchmarking/suite.rb +0 -24
  39. data/benchmarking/worker.rb +0 -71
  40. data/examples/basic.rb +0 -15
  41. data/examples/consistency.rb +0 -114
  42. data/examples/dist_redis.rb +0 -43
  43. data/examples/incr-decr.rb +0 -17
  44. data/examples/list.rb +0 -26
  45. data/examples/pubsub.rb +0 -37
  46. data/examples/sentinel.rb +0 -41
  47. data/examples/sentinel/sentinel.conf +0 -9
  48. data/examples/sentinel/start +0 -49
  49. data/examples/sets.rb +0 -36
  50. data/examples/unicorn/config.ru +0 -3
  51. data/examples/unicorn/unicorn.rb +0 -20
  52. data/redis.gemspec +0 -44
  53. data/test/bitpos_test.rb +0 -69
  54. data/test/blocking_commands_test.rb +0 -42
  55. data/test/client_test.rb +0 -59
  56. data/test/command_map_test.rb +0 -30
  57. data/test/commands_on_hashes_test.rb +0 -21
  58. data/test/commands_on_hyper_log_log_test.rb +0 -21
  59. data/test/commands_on_lists_test.rb +0 -20
  60. data/test/commands_on_sets_test.rb +0 -77
  61. data/test/commands_on_sorted_sets_test.rb +0 -137
  62. data/test/commands_on_strings_test.rb +0 -101
  63. data/test/commands_on_value_types_test.rb +0 -133
  64. data/test/connection_handling_test.rb +0 -277
  65. data/test/connection_test.rb +0 -57
  66. data/test/db/.gitkeep +0 -0
  67. data/test/distributed_blocking_commands_test.rb +0 -46
  68. data/test/distributed_commands_on_hashes_test.rb +0 -10
  69. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  70. data/test/distributed_commands_on_lists_test.rb +0 -22
  71. data/test/distributed_commands_on_sets_test.rb +0 -83
  72. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  73. data/test/distributed_commands_on_strings_test.rb +0 -59
  74. data/test/distributed_commands_on_value_types_test.rb +0 -95
  75. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  76. data/test/distributed_connection_handling_test.rb +0 -23
  77. data/test/distributed_internals_test.rb +0 -79
  78. data/test/distributed_key_tags_test.rb +0 -52
  79. data/test/distributed_persistence_control_commands_test.rb +0 -26
  80. data/test/distributed_publish_subscribe_test.rb +0 -92
  81. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  82. data/test/distributed_scripting_test.rb +0 -102
  83. data/test/distributed_sorting_test.rb +0 -20
  84. data/test/distributed_test.rb +0 -58
  85. data/test/distributed_transactions_test.rb +0 -32
  86. data/test/encoding_test.rb +0 -18
  87. data/test/error_replies_test.rb +0 -59
  88. data/test/fork_safety_test.rb +0 -65
  89. data/test/helper.rb +0 -232
  90. data/test/helper_test.rb +0 -24
  91. data/test/internals_test.rb +0 -417
  92. data/test/lint/blocking_commands.rb +0 -150
  93. data/test/lint/hashes.rb +0 -162
  94. data/test/lint/hyper_log_log.rb +0 -60
  95. data/test/lint/lists.rb +0 -143
  96. data/test/lint/sets.rb +0 -140
  97. data/test/lint/sorted_sets.rb +0 -316
  98. data/test/lint/strings.rb +0 -260
  99. data/test/lint/value_types.rb +0 -122
  100. data/test/persistence_control_commands_test.rb +0 -26
  101. data/test/pipelining_commands_test.rb +0 -242
  102. data/test/publish_subscribe_test.rb +0 -282
  103. data/test/remote_server_control_commands_test.rb +0 -118
  104. data/test/scanning_test.rb +0 -413
  105. data/test/scripting_test.rb +0 -78
  106. data/test/sentinel_command_test.rb +0 -80
  107. data/test/sentinel_test.rb +0 -255
  108. data/test/sorting_test.rb +0 -59
  109. data/test/ssl_test.rb +0 -73
  110. data/test/support/connection/hiredis.rb +0 -1
  111. data/test/support/connection/ruby.rb +0 -1
  112. data/test/support/connection/synchrony.rb +0 -17
  113. data/test/support/redis_mock.rb +0 -130
  114. data/test/support/ssl/gen_certs.sh +0 -31
  115. data/test/support/ssl/trusted-ca.crt +0 -25
  116. data/test/support/ssl/trusted-ca.key +0 -27
  117. data/test/support/ssl/trusted-cert.crt +0 -81
  118. data/test/support/ssl/trusted-cert.key +0 -28
  119. data/test/support/ssl/untrusted-ca.crt +0 -26
  120. data/test/support/ssl/untrusted-ca.key +0 -27
  121. data/test/support/ssl/untrusted-cert.crt +0 -82
  122. data/test/support/ssl/untrusted-cert.key +0 -28
  123. data/test/support/wire/synchrony.rb +0 -24
  124. data/test/support/wire/thread.rb +0 -5
  125. data/test/synchrony_driver.rb +0 -88
  126. data/test/test.conf.erb +0 -9
  127. data/test/thread_safety_test.rb +0 -62
  128. data/test/transactions_test.rb +0 -264
  129. data/test/unknown_commands_test.rb +0 -14
  130. data/test/url_param_test.rb +0 -138
@@ -1,27 +0,0 @@
1
- -----BEGIN RSA PRIVATE KEY-----
2
- MIIEpAIBAAKCAQEArV8XBBlKxqgKpQSveAfCMEpAfDpy2Av3P+k3XlhuOqc5mVmb
3
- 334tGpHCirm0TXH6Grzrqi7jZ6UA5CJZyd+yvy2ZPEOfmjKFBgYkNo0jde9O7Bah
4
- 93kxb1zlM5QxHLAWu2O0bmiPEl4NVBrJ5wnI+h9wVtsSnFzzev7N9L4TcNgj6rV5
5
- uDTg92W+RZAfXqQBHo0YNDj5+Qyd5hElafx9hKpKbTGfunDpNvwjHHvAAH3MQRsC
6
- rjjFzTg7M0zcTfjrhghzscfPr0f3ld+baJyEsG5JjvViOgwvqVk9rD7w4bkLarK1
7
- aHwj/6Yq3m+Qnv+2z/xbGXDUjDH1eXaaJ3GK6wIDAQABAoIBAQCeC0QxAVlwNTnW
8
- 6qmGsxPr75RPavzMREQ1p8VIpTZ/E3hneg+lMiGtydhdnCJoQxGrFDOFJU86aWmh
9
- jkrpw5nvu4KoNEEnUQyAzFJwxELiPLBmec9WiM1u5nEujtYif8eJNcACsiBSrxhZ
10
- Zj5N9laW5NgE5ZpWnkl7AxL/G9MfFvifr9KtyDcs+wnYD6ffz/bRwS54veMccj/q
11
- SkVQRL7FM4NJczG0TTp+LT/1R3s8YVv9GHnJ6K7Gol3E0PbFS1HztDuMVonhWiac
12
- 9Rjt7w0rNgeH6ZbCMXrUd+8I8amazA78p1ky0Mh8d6UUVFU1jjtyxlgDh06IPsnE
13
- +exeAClxAoGBAOMZ7LEFr3VcFwym7RvgckeQhd6Rmz8Bh7kGfB9pDsHFprGJ0rm4
14
- XgNETJXOky5wUCPZmMBN1iAU/ehyyXqPykXiKjAQLxQNHR9/Z6P58PsHs2Uw8VZa
15
- XdZwlBME5+/yl5DiirO5rCt804DdCQgSu7denudwWbbtzAsodSKj5zEJAoGBAMNu
16
- 21hZnsvhtZlvQVHZ4sQttrv9e5VpWWHkDPRN3sdLZPfK/+3L0BmUrGotgNWpTZwR
17
- 8YvKRT2Xn1unzpKlkHtIVuHU7khOj+tYHLIx3rezVanw9QzbIANMel6STlUr3jwX
18
- fjnibgkJixxHTOBs8/zm219Q1sNTos9GUOAZQb1TAoGALwGFsVpo59TI3JCMkXGS
19
- led/HgNra84oRo7mECZRrJ/5kdPiLxjPNMPlSji41CrhG5qFeIBj6r4NlBh2RY0P
20
- pAldDBe9dtwEBCn9zL4GOB9u7WoE+ge4VpN0wr8INu0ynAWYCf1LerDaolid7vLZ
21
- sem+4E6r8yYjTsfv/tyIFOkCgYEAlCZobxxZLbNn5+2X9cWXiyIgYXgyBDy9fmDT
22
- lSum0yuLWfDwfELB+XJkFYVzIgVbCRHtKwxl2uAi9OdLyI1r7pkTC9VP4U50+XJt
23
- JoR5koaHTPGVwm4mYXnLVf/RE+3SZXllvdmxknZCl2hRldviRfh3mlT8yUuQo1Jp
24
- oshitnMCgYAXTQLA7B5YLmhCG8HRM/h/xM55ObdDX1SIWUbk3p1uxak1W0abfvpi
25
- FPBy2riOdSDA6Uv7V8y1j4tENGVMyyMsEpFdLDX4Lkbh9niOoPeHCWdO0boPk0Fw
26
- aPXtT7gdTPWJulKOxtLuGqBjZZ77TO49uqWlEMaerulWyjhRm8zzvA==
27
- -----END RSA PRIVATE KEY-----
@@ -1,82 +0,0 @@
1
- Certificate:
2
- Data:
3
- Version: 3 (0x2)
4
- Serial Number: 9801410922913464933 (0x88059b4de5e40265)
5
- Signature Algorithm: sha1WithRSAEncryption
6
- Issuer: C=XX, ST=Untrusted, L=Evilville, O=Evil Hacker, OU=Attack Department, CN=127.0.0.1
7
- Validity
8
- Not Before: Apr 2 03:34:51 2016 GMT
9
- Not After : Jun 23 03:34:51 2050 GMT
10
- Subject: C=XX, ST=Untrusted, O=Evil Hacker, OU=Attack Department, CN=127.0.0.1
11
- Subject Public Key Info:
12
- Public Key Algorithm: rsaEncryption
13
- Public-Key: (2048 bit)
14
- Modulus:
15
- 00:9a:73:e7:45:fc:d3:b5:4a:bd:bd:ad:30:e5:24:
16
- 74:38:01:89:8f:a9:90:bf:3c:4a:bf:d1:f1:5e:db:
17
- c8:aa:26:59:e6:ec:b3:a0:0f:4d:74:59:dd:c9:27:
18
- 2f:e1:48:7d:30:d9:59:06:2f:29:f0:d1:25:33:79:
19
- 5f:58:9d:d7:54:c8:a7:aa:1a:84:00:a2:85:63:32:
20
- cc:ef:73:7d:b0:26:c6:95:f1:86:16:68:38:63:57:
21
- 09:0d:6f:6a:70:e8:75:3b:72:b4:b1:4d:01:0e:01:
22
- 0e:bf:bf:6a:8c:88:fe:0d:cb:88:43:1b:da:ed:0c:
23
- 88:25:33:f7:b9:b1:fc:32:b8:94:c9:20:7c:ac:49:
24
- e4:c1:58:93:69:0e:41:e3:df:96:e3:47:11:14:8c:
25
- e4:4b:b6:56:df:6f:5e:d2:48:dc:a1:8a:98:cc:4b:
26
- 02:89:95:ea:f6:de:a5:3a:9c:06:7c:f0:7c:09:6f:
27
- 27:11:f2:b1:1b:47:6b:a3:ea:d6:ee:a1:65:91:84:
28
- cf:2e:81:d3:55:4a:e8:01:4e:72:41:ac:92:e0:7d:
29
- 7c:fe:85:f0:2e:f1:ee:4a:80:f9:4e:5a:b4:95:6c:
30
- bb:fe:ff:46:58:4a:7b:fc:a0:63:59:5d:01:5b:63:
31
- 06:5c:94:83:30:27:81:f0:1a:13:89:5a:5a:a2:e2:
32
- 0f:eb
33
- Exponent: 65537 (0x10001)
34
- X509v3 extensions:
35
- X509v3 Basic Constraints:
36
- CA:FALSE
37
- Netscape Comment:
38
- OpenSSL Generated Certificate
39
- X509v3 Subject Key Identifier:
40
- 1B:71:91:99:43:12:0F:D3:59:FC:00:EF:99:F3:42:CF:41:FD:40:1D
41
- X509v3 Authority Key Identifier:
42
- keyid:B7:83:36:F2:A9:24:A9:AE:C8:FB:1A:99:AC:76:01:94:E2:8D:D9:30
43
-
44
- Signature Algorithm: sha1WithRSAEncryption
45
- a4:cd:88:c3:19:b7:cd:7e:7a:e7:85:1f:fb:3e:31:0b:ff:9d:
46
- 6f:b1:a2:72:56:4a:b1:ec:6c:f3:99:bd:65:08:0a:e9:47:1d:
47
- 79:55:5b:29:b1:d4:85:69:85:65:3f:30:37:a1:0e:76:d2:1f:
48
- b0:76:2a:23:75:c9:05:a4:89:cf:c1:68:42:16:46:d6:c9:a8:
49
- e5:06:5b:52:45:d4:41:5d:f3:c7:00:d1:ca:cc:3e:4c:63:e6:
50
- 7a:fe:ce:20:a4:df:e3:7c:e3:75:6e:f7:18:84:1c:9b:56:ce:
51
- 55:fb:04:b9:de:11:6e:7d:5d:47:de:a9:ed:3e:79:48:a5:4f:
52
- 32:d5:96:8d:ea:e2:a6:8a:c2:e9:f5:b0:8d:da:ef:71:96:60:
53
- b0:7e:c3:3d:e9:37:91:27:bf:ae:5c:e8:c0:9a:6f:c8:38:62:
54
- 90:d0:49:c1:7f:28:13:da:29:bb:5b:d1:72:6f:23:7c:a0:87:
55
- 44:96:47:53:0e:0d:1d:74:d9:26:6b:b3:01:24:9c:5e:c8:f4:
56
- 11:fe:35:14:6c:ec:e7:42:5f:32:56:f0:9d:8d:11:02:21:07:
57
- cc:ce:7b:f0:e9:bc:83:c8:93:b0:8c:a7:e9:b1:c2:12:6b:30:
58
- 2b:75:dc:61:b8:d4:87:6b:07:2d:75:b0:7a:18:6e:19:7f:04:
59
- 78:c6:c7:b7
60
- -----BEGIN CERTIFICATE-----
61
- MIID4jCCAsqgAwIBAgIJAIgFm03l5AJlMA0GCSqGSIb3DQEBBQUAMHsxCzAJBgNV
62
- BAYTAlhYMRIwEAYDVQQIEwlVbnRydXN0ZWQxEjAQBgNVBAcTCUV2aWx2aWxsZTEU
63
- MBIGA1UEChMLRXZpbCBIYWNrZXIxGjAYBgNVBAsTEUF0dGFjayBEZXBhcnRtZW50
64
- MRIwEAYDVQQDEwkxMjcuMC4wLjEwIBcNMT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1fHDhob7EvyMMwzmDCPpQnN/6KXRzapu2MDFvlMkEMITTN7J0En
16
- c9BOxo06Q4DKXGVCiWmbIwXihQKBgQDER/KfaWRZWOA2mQ26giJVjUX4+s1GeQM0
17
- V4AIo1KS6fDzh68RsAQpMTx/N8aHEcxf+2qGIOTCvFY3Nxqe5aw/Xiz47MPlYulM
18
- OecovSO96nidhyv2Zux+HpvI85tcWTyORi+RWho51gTOLth6BJ4uvSsaooWmO0Va
19
- GoIxKcaLrwKBgH/guuWHWy8DG5H3fRE1FFA8cc+iN5HMC2NBYNRIGddME+BblznE
20
- WS1ghtXRWJnddPmLPAzLxqdJ28W7ZsyUPWKy3i0HGfjJF1jKb/KX32JAbfC2xOT7
21
- DK1TgWBtGZtH1EPK2rkqvxLPB0Y/lhG4aF0Jl++LmH9dhf5mAr8zzXGNAoGBAKEi
22
- l7H66aDX76mi2LxmnR0yz2DpNKBINDNCKh/tRJrLZz3mA/k3URMoEow2E8tK90dM
23
- tVTLqEGeMAFAQaB02IVlIPJyHRgxrWkgl/6/15nP5ZkdISA1uqyHIElGhCK6N5Zt
24
- VBu1ppYYdvV1S85QADRKpBpHlgSz3+lqnbsSmqaNAoGAacA3XSIzTHj6+06VzEHN
25
- aO2LJbBxl6Eduj6eTEgcZBlQOX6cVvaleTAT2g2xM0aGMV4StmdijUdktjBQVLpH
26
- 8PBTqlfVuLXEXQd+qWMpUJwEkh/pdmf9EPoLSfp3zQLaNI/kCg3jQtR4n6/68hfi
27
- 5Q6L0mN+SoB+jRNPDSV7JWA=
28
- -----END PRIVATE KEY-----
@@ -1,24 +0,0 @@
1
- class Wire < Fiber
2
- # We cannot run this fiber explicitly because EM schedules it. Resuming the
3
- # current fiber on the next tick to let the reactor do work.
4
- def self.pass
5
- f = Fiber.current
6
- EM.next_tick { f.resume }
7
- Fiber.yield
8
- end
9
-
10
- def self.sleep(sec)
11
- EM::Synchrony.sleep(sec)
12
- end
13
-
14
- def initialize(&blk)
15
- super
16
-
17
- # Schedule run in next tick
18
- EM.next_tick { resume }
19
- end
20
-
21
- def join
22
- self.class.pass while alive?
23
- end
24
- end
@@ -1,5 +0,0 @@
1
- class Wire < Thread
2
- def self.sleep(sec)
3
- Kernel.sleep(sec)
4
- end
5
- end
@@ -1,88 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'em-synchrony'
4
- require 'em-synchrony/connection_pool'
5
-
6
- require 'redis'
7
- require 'redis/connection/synchrony'
8
-
9
-
10
- require File.expand_path("./helper", File.dirname(__FILE__))
11
-
12
- PORT = 6381
13
- OPTIONS = {:port => PORT, :db => 15}
14
-
15
- #
16
- # if running under Eventmachine + Synchrony (Ruby 1.9+), then
17
- # we can simulate the blocking API while performing the network
18
- # IO via the EM reactor.
19
- #
20
-
21
- EM.synchrony do
22
- r = Redis.new OPTIONS
23
- r.flushdb
24
-
25
- r.rpush "foo", "s1"
26
- r.rpush "foo", "s2"
27
-
28
- assert_equal 2, r.llen("foo")
29
- assert_equal "s2", r.rpop("foo")
30
-
31
- r.set("foo", "bar")
32
-
33
- assert_equal "bar", r.getset("foo", "baz")
34
- assert_equal "baz", r.get("foo")
35
-
36
- r.set("foo", "a")
37
-
38
- assert_equal 1, r.getbit("foo", 1)
39
- assert_equal 1, r.getbit("foo", 2)
40
- assert_equal 0, r.getbit("foo", 3)
41
- assert_equal 0, r.getbit("foo", 4)
42
- assert_equal 0, r.getbit("foo", 5)
43
- assert_equal 0, r.getbit("foo", 6)
44
- assert_equal 1, r.getbit("foo", 7)
45
-
46
- r.flushdb
47
-
48
- # command pipelining
49
- r.pipelined do
50
- r.lpush "foo", "s1"
51
- r.lpush "foo", "s2"
52
- end
53
-
54
- assert_equal 2, r.llen("foo")
55
- assert_equal "s2", r.lpop("foo")
56
- assert_equal "s1", r.lpop("foo")
57
-
58
- assert_equal "OK", r.client.call(:quit)
59
- assert_equal "PONG", r.ping
60
-
61
-
62
- rpool = EM::Synchrony::ConnectionPool.new(size: 5) { Redis.new OPTIONS }
63
-
64
- result = rpool.watch 'foo' do |rd|
65
- assert_kind_of Redis, rd
66
-
67
- rd.set "foo", "s1"
68
- rd.multi do |multi|
69
- multi.set "foo", "s2"
70
- end
71
- end
72
-
73
- assert_equal nil, result
74
- assert_equal "s1", rpool.get("foo")
75
-
76
- result = rpool.watch "foo" do |rd|
77
- assert_kind_of Redis, rd
78
-
79
- rd.multi do |multi|
80
- multi.set "foo", "s3"
81
- end
82
- end
83
-
84
- assert_equal ["OK"], result
85
- assert_equal "s3", rpool.get("foo")
86
-
87
- EM.stop
88
- end
data/test/test.conf.erb DELETED
@@ -1,9 +0,0 @@
1
- dir <%= REDIS_DIR %>
2
- pidfile <%= REDIS_PID %>
3
- port 6381
4
- unixsocket <%= REDIS_SOCKET %>
5
- timeout 300
6
- loglevel debug
7
- logfile <%= REDIS_LOG %>
8
- databases 16
9
- daemonize yes
@@ -1,62 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestThreadSafety < Test::Unit::TestCase
6
-
7
- include Helper::Client
8
-
9
- driver(:ruby, :hiredis) do
10
- def test_thread_safety
11
- redis = Redis.new(OPTIONS)
12
- redis.set "foo", 1
13
- redis.set "bar", 2
14
-
15
- sample = 100
16
-
17
- t1 = Thread.new do
18
- $foos = Array.new(sample) { redis.get "foo" }
19
- end
20
-
21
- t2 = Thread.new do
22
- $bars = Array.new(sample) { redis.get "bar" }
23
- end
24
-
25
- t1.join
26
- t2.join
27
-
28
- assert_equal ["1"], $foos.uniq
29
- assert_equal ["2"], $bars.uniq
30
- end
31
-
32
- def test_thread_safety_queue_commit
33
- redis = Redis.new(OPTIONS)
34
- redis.set "foo", 1
35
- redis.set "bar", 2
36
-
37
- sample = 100
38
-
39
- t1 = Thread.new do
40
- sample.times do
41
- r.queue("get", "foo")
42
- end
43
-
44
- $foos = r.commit
45
- end
46
-
47
- t2 = Thread.new do
48
- sample.times do
49
- r.queue("get", "bar")
50
- end
51
-
52
- $bars = r.commit
53
- end
54
-
55
- t1.join
56
- t2.join
57
-
58
- assert_equal ["1"], $foos.uniq
59
- assert_equal ["2"], $bars.uniq
60
- end
61
- end
62
- end
@@ -1,264 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestTransactions < Test::Unit::TestCase
6
-
7
- include Helper::Client
8
-
9
- def test_multi_discard
10
- r.multi
11
-
12
- assert_equal "QUEUED", r.set("foo", "1")
13
- assert_equal "QUEUED", r.get("foo")
14
-
15
- r.discard
16
-
17
- assert_equal nil, r.get("foo")
18
- end
19
-
20
- def test_multi_exec_with_a_block
21
- r.multi do |multi|
22
- multi.set "foo", "s1"
23
- end
24
-
25
- assert_equal "s1", r.get("foo")
26
- end
27
-
28
- def test_multi_exec_with_a_block_doesn_t_return_replies_for_multi_and_exec
29
- r1, r2, nothing_else = r.multi do |multi|
30
- multi.set "foo", "s1"
31
- multi.get "foo"
32
- end
33
-
34
- assert_equal "OK", r1
35
- assert_equal "s1", r2
36
- assert_equal nil, nothing_else
37
- end
38
-
39
- def test_assignment_inside_multi_exec_block
40
- r.multi do |m|
41
- @first = m.sadd("foo", 1)
42
- @second = m.sadd("foo", 1)
43
- end
44
-
45
- assert_equal true, @first.value
46
- assert_equal false, @second.value
47
- end
48
-
49
- # Although we could support accessing the values in these futures,
50
- # it doesn't make a lot of sense.
51
- def test_assignment_inside_multi_exec_block_with_delayed_command_errors
52
- assert_raise(Redis::CommandError) do
53
- r.multi do |m|
54
- @first = m.set("foo", "s1")
55
- @second = m.incr("foo") # not an integer
56
- @third = m.lpush("foo", "value") # wrong kind of value
57
- end
58
- end
59
-
60
- assert_equal "OK", @first.value
61
- assert_raise(Redis::CommandError) { @second.value }
62
- assert_raise(Redis::FutureNotReady) { @third.value }
63
- end
64
-
65
- def test_assignment_inside_multi_exec_block_with_immediate_command_errors
66
- assert_raise(Redis::CommandError) do
67
- r.multi do |m|
68
- m.doesnt_exist
69
- @first = m.sadd("foo", 1)
70
- @second = m.sadd("foo", 1)
71
- end
72
- end
73
-
74
- assert_raise(Redis::FutureNotReady) { @first.value }
75
- assert_raise(Redis::FutureNotReady) { @second.value }
76
- end
77
-
78
- def test_raise_immediate_errors_in_multi_exec
79
- assert_raise(RuntimeError) do
80
- r.multi do |multi|
81
- multi.set "bar", "s2"
82
- raise "Some error"
83
- multi.set "baz", "s3"
84
- end
85
- end
86
-
87
- assert_equal nil, r.get("bar")
88
- assert_equal nil, r.get("baz")
89
- end
90
-
91
- def test_transformed_replies_as_return_values_for_multi_exec_block
92
- info, _ = r.multi do |m|
93
- r.info
94
- end
95
-
96
- assert info.kind_of?(Hash)
97
- end
98
-
99
- def test_transformed_replies_inside_multi_exec_block
100
- r.multi do |m|
101
- @info = r.info
102
- end
103
-
104
- assert @info.value.kind_of?(Hash)
105
- end
106
-
107
- def test_raise_command_errors_in_multi_exec
108
- assert_raise(Redis::CommandError) do
109
- r.multi do |m|
110
- m.set("foo", "s1")
111
- m.incr("foo") # not an integer
112
- m.lpush("foo", "value") # wrong kind of value
113
- end
114
- end
115
-
116
- assert_equal "s1", r.get("foo")
117
- end
118
-
119
- def test_raise_command_errors_when_accessing_futures_after_multi_exec
120
- begin
121
- r.multi do |m|
122
- m.set("foo", "s1")
123
- @counter = m.incr("foo") # not an integer
124
- end
125
- rescue Exception
126
- # Not gonna deal with it
127
- end
128
-
129
- # We should test for Redis::Error here, but hiredis doesn't yet do
130
- # custom error classes.
131
- err = nil
132
- begin
133
- @counter.value
134
- rescue => err
135
- end
136
-
137
- assert err.kind_of?(RuntimeError)
138
- end
139
-
140
- def test_multi_with_a_block_yielding_the_client
141
- r.multi do |multi|
142
- multi.set "foo", "s1"
143
- end
144
-
145
- assert_equal "s1", r.get("foo")
146
- end
147
-
148
- def test_raise_command_error_when_exec_fails
149
- redis_mock(:exec => lambda { |*_| "-ERROR" }) do |redis|
150
- assert_raise(Redis::CommandError) do
151
- redis.multi do |m|
152
- m.set "foo", "s1"
153
- end
154
- end
155
- end
156
- end
157
-
158
- def test_watch
159
- res = r.watch "foo"
160
-
161
- assert_equal "OK", res
162
- end
163
-
164
- def test_watch_with_an_unmodified_key
165
- r.watch "foo"
166
- r.multi do |multi|
167
- multi.set "foo", "s1"
168
- end
169
-
170
- assert_equal "s1", r.get("foo")
171
- end
172
-
173
- def test_watch_with_an_unmodified_key_passed_as_array
174
- r.watch ["foo", "bar"]
175
- r.multi do |multi|
176
- multi.set "foo", "s1"
177
- end
178
-
179
- assert_equal "s1", r.get("foo")
180
- end
181
-
182
- def test_watch_with_a_modified_key
183
- r.watch "foo"
184
- r.set "foo", "s1"
185
- res = r.multi do |multi|
186
- multi.set "foo", "s2"
187
- end
188
-
189
- assert_equal nil, res
190
- assert_equal "s1", r.get("foo")
191
- end
192
-
193
- def test_watch_with_a_modified_key_passed_as_array
194
- r.watch ["foo", "bar"]
195
- r.set "foo", "s1"
196
- res = r.multi do |multi|
197
- multi.set "foo", "s2"
198
- end
199
-
200
- assert_equal nil, res
201
- assert_equal "s1", r.get("foo")
202
- end
203
-
204
- def test_watch_with_a_block_and_an_unmodified_key
205
- result = r.watch "foo" do |rd|
206
-
207
- assert_same r, rd
208
-
209
- rd.multi do |multi|
210
- multi.set "foo", "s1"
211
- end
212
- end
213
-
214
- assert_equal ["OK"], result
215
- assert_equal "s1", r.get("foo")
216
- end
217
-
218
- def test_watch_with_a_block_and_a_modified_key
219
- result = r.watch "foo" do |rd|
220
-
221
- assert_same r, rd
222
-
223
- rd.set "foo", "s1"
224
- rd.multi do |multi|
225
- multi.set "foo", "s2"
226
- end
227
- end
228
-
229
- assert_equal nil, result
230
- assert_equal "s1", r.get("foo")
231
- end
232
-
233
- def test_watch_with_a_block_that_raises_an_exception
234
- r.set("foo", "s1")
235
-
236
- begin
237
- r.watch "foo" do
238
- raise "test"
239
- end
240
- rescue RuntimeError
241
- end
242
-
243
- r.set("foo", "s2")
244
-
245
- # If the watch was still set from within the block above, this multi/exec
246
- # would fail. This proves that raising an exception above unwatches.
247
- r.multi do |multi|
248
- multi.set "foo", "s3"
249
- end
250
-
251
- assert_equal "s3", r.get("foo")
252
- end
253
-
254
- def test_unwatch_with_a_modified_key
255
- r.watch "foo"
256
- r.set "foo", "s1"
257
- r.unwatch
258
- r.multi do |multi|
259
- multi.set "foo", "s2"
260
- end
261
-
262
- assert_equal "s2", r.get("foo")
263
- end
264
- end