redic 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 982edbdc6b3b3ca417621ca43967117805d0faa9
4
- data.tar.gz: 2f4b5a8ee99890f5e432cf5606984a3f683303de
3
+ metadata.gz: 3ba65ff4580315a8788983af009026bff12e3634
4
+ data.tar.gz: 24bdd4a1198cdcce1b5b2a961037f1a0708ae803
5
5
  SHA512:
6
- metadata.gz: b4e520979e52233b4137c02463ea4fd6d1a7a222e3ec6665999fce604ed534a99ef36d05253bcce0255f7fec16a557dfc6b81f78e340c2dceb8a70b6ed9694e5
7
- data.tar.gz: 080f253def0a1a5d0c7357a81b989a523a557e40de9b1d254fa0ef96c993b2738ed9e81be8656e27a031ff2ae7c3e1648a18f83c133c8a84c07e52a423965541
6
+ metadata.gz: 705de80d86e04f31637b4ea76496b69afff0e79e631d8fe5d312c2083d739abb88c1023760372d15d843b621b39d216c16c4e4b4edce88afc83e13f03a347527
7
+ data.tar.gz: 784f89f58b9bfec889c7f88884fa1ffed28bec17f1b30843f2cf1338dde46bafcf1e908df6c6346fb99aea80aadde5dc4e17e4c974252e0707e6b63da9b082ca
@@ -39,30 +39,29 @@ class Redic
39
39
  raise err, "Can't connect to: %s" % @uri
40
40
  end
41
41
 
42
- authenticate
43
- select
44
- end
45
-
46
- def authenticate
47
- if @uri.password
48
- @semaphore.synchronize do
49
- write ["AUTH", @uri.password]
50
- read
51
- end
42
+ if @uri.scheme == "redis"
43
+ @uri.password && assert_ok(call("AUTH", @uri.password))
44
+ @uri.path && assert_ok(call("SELECT", @uri.path[1..-1]))
52
45
  end
53
46
  end
54
47
 
55
- def select
56
- if @uri.path
57
- @semaphore.synchronize do
58
- write ["SELECT", @uri.path[1..-1]]
59
- read
60
- end
48
+ def call(*args)
49
+ @semaphore.synchronize do
50
+ write(args)
51
+ read
61
52
  end
62
53
  end
63
54
 
64
55
  def connected?
65
56
  @connection && @connection.connected?
66
57
  end
58
+
59
+ def assert(value, error)
60
+ raise error unless value
61
+ end
62
+
63
+ def assert_ok(reply)
64
+ assert(reply == "OK", reply)
65
+ end
67
66
  end
68
67
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "redic"
5
- s.version = "1.0.0"
5
+ s.version = "1.0.1"
6
6
  s.summary = "Lightweight Redis Client"
7
7
  s.description = "Lightweight Redis Client"
8
8
  s.authors = ["Michel Martens", "Cyril David"]
@@ -15,7 +15,48 @@ test "url" do |c|
15
15
  assert_equal "redis://localhost:6379/", c.url
16
16
  end
17
17
 
18
+ test "select db from url" do |c1|
19
+
20
+ # Connect to db 1
21
+ c2 = Redic.new("redis://localhost:6379/2")
22
+
23
+ c2.call("FLUSHDB")
24
+
25
+ # Set a value in db 0
26
+ c1.call("SET", "foo", "bar")
27
+
28
+ assert_equal(1, c1.call("DBSIZE"))
29
+ assert_equal(0, c2.call("DBSIZE"))
30
+ end
31
+
32
+ test "error when selecting db from url" do
33
+ c2 = Redic.new("redis://localhost:6379/foo")
34
+
35
+ assert_raise(RuntimeError) do
36
+
37
+ # Connection is lazy, send a command
38
+ c2.call("PING")
39
+ end
40
+ end
41
+
42
+ test "error when authenticating from url" do
43
+
44
+ # The correct password for 6380 is "foo"
45
+ c2 = Redic.new("redis://:foo@localhost:6380/")
46
+ c2.call("PING")
47
+
48
+ # The password provided is wrong
49
+ c3 = Redic.new("redis://:bar@localhost:6380/")
50
+
51
+ assert_raise(RuntimeError) do
52
+
53
+ # Connection is lazy, send a command
54
+ c3.call("PING")
55
+ end
56
+ end
57
+
18
58
  test "timeout" do |c1|
59
+
19
60
  # Default timeout is 10 seconds
20
61
  assert_equal 10_000_000, c1.timeout
21
62
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens