uri-redis 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fa796076bf7ed89fabf28ff901ecce357f10d1a93b09dada70b8ba2185f8bff
4
- data.tar.gz: 16b72d3fd5d6a4e41e95e8195a0633d7784245a6eb3d272da476a27845473e36
3
+ metadata.gz: a7c320d796599dbe819c6f6f42ab5655fd476c6c4c14fbb5e2e06b96d406ed0b
4
+ data.tar.gz: 82a9de5b109832c565cbded9aa9311020bf4937b27959086941582caa5c3403c
5
5
  SHA512:
6
- metadata.gz: 38b55796fce214f4093f75284e2216a673794c383a9068c79bb6bda833352e9d97d4396b54e06a27fd29c9114fda246923979bc255b4d263e44340ad6a9431d5
7
- data.tar.gz: b7d135ac66b84e03759185c42022cc01106d71cee2ac72b3c07f57caf306db7f367a9eb53c76fb1f53c3f54eb9a61f7c6759009106722a7dd826be5389dfc8b2
6
+ metadata.gz: b7a975c5b9aadd178da1f52d25910dc4b9bfd33b065cfbd876dfd4b622de860a2a31e0a99e2e30b541ed72571a1713a00981f0774f7ce932c41ac221077589b4
7
+ data.tar.gz: ae0da4815dddaa945093437f9ec2df218ec0e29be9b4f73cef0460d9046038d0933e4eb4e28f01b60b84d1550ae7c1e28ecb344026c4fae1dd27c01aebb89dbe
data/CHANGES.txt CHANGED
@@ -1,5 +1,9 @@
1
1
  URI-Redis, CHANGES
2
2
 
3
+ #### 1.3.0 (2024-06-15) ###############################
4
+
5
+ * Add support for rediss scheme (thanks @sebastien-coavoux).
6
+
3
7
  #### 1.2.0 (2024-05-20) ###############################
4
8
 
5
9
  * Fix for Ruby <= 3.0 `register_scheme` error.
data/Gemfile CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rake", "~> 13.0"
6
5
  gem "redis", ">= 4.8", "< 7"
7
- gem "rubocop", "~> 1.21"
8
6
 
9
7
  group :development do
8
+ gem "rake", "~> 13.0"
9
+ gem "rubocop", "~> 1.21"
10
10
  gem "tryouts", "~>2.2.0"
11
11
  end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # URI-Redis v1.2 (2024-05-20)
1
+ # URI-Redis v1.3 (2024-06-15)
2
2
 
3
3
  Creates a URI object for Redis URLs.
4
4
 
@@ -12,11 +12,23 @@ e.g.
12
12
  require 'uri/redis'
13
13
 
14
14
  conf = URI.parse 'redis://localhost:4380/2'
15
+ conf.scheme # => "redis"
15
16
  conf.host # => localhost
16
17
  conf.port # => 4380
17
18
  conf.db # => 2
18
19
  conf.to_s # => redis://localhost:4380/2
19
- conf
20
+ ```
21
+
22
+ ### SSL Support
23
+
24
+ SSL is supported by using the `rediss` scheme. Note: SSL support is only available in Redis (Server) 6.0 and later and via redis-rb 4.7 and later.
25
+
26
+ ```ruby
27
+ require 'uri/redis'
28
+
29
+ conf = URI.parse 'rediss://localhost:4380/2'
30
+ conf.scheme # => "rediss"
31
+ conf.to_s # => rediss://localhost:4380/2
20
32
  ```
21
33
 
22
34
 
@@ -25,7 +37,7 @@ e.g.
25
37
  Get it in one of the following ways:
26
38
 
27
39
  * `gem install uri-redis`
28
- * `git clone git+ssh://github.com/delano/uri-redis.git`
40
+ * `git clone git@github.com:delano/uri-redis.git`
29
41
 
30
42
 
31
43
  ## About
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "uri/generic"
4
+
3
5
  module URI
4
- module Redis
5
- VERSION = "1.2.0"
6
+ class Redis < URI::Generic
7
+ VERSION = "1.3.0"
6
8
  SUMMARY = "A Ruby library for parsing, building and normalizing redis URLs"
7
9
  end
8
10
  end
data/lib/uri/redis.rb CHANGED
@@ -66,14 +66,16 @@ module URI
66
66
  hsh = {
67
67
  host: host,
68
68
  port: port,
69
- db: db
69
+ db: db,
70
+ ssl: scheme == 'rediss'
70
71
  }.merge(parse_query(query))
71
72
  hsh[:password] = password if password
73
+ hsh[:timeout] = hsh[:timeout].to_i if hsh.key?(:timeout)
72
74
  hsh
73
75
  end
74
76
 
75
77
  def serverid
76
- format("redis://%s:%s/%s", host, port, db)
78
+ format('%s://%s:%s/%s', scheme, host, port, db)
77
79
  end
78
80
 
79
81
  private
@@ -102,26 +104,20 @@ module URI
102
104
 
103
105
  if URI.respond_to?(:register_scheme)
104
106
  URI.register_scheme "REDIS", Redis
107
+ URI.register_scheme "REDISS", Redis
105
108
  else
106
109
  @@schemes['REDIS'] = Redis
110
+ @@schemes['REDISS'] = Redis
107
111
  end
108
112
  end
109
113
 
110
114
  # Adds a URI method to Redis
111
115
  class Redis
112
116
  def self.uri(conf = {})
113
- URI.parse format("redis://%s:%s/%s", conf[:host], conf[:port], conf[:db])
117
+ URI.parse format("%s://%s:%s/%s", conf[:ssl] ? 'rediss' : 'redis', conf[:host], conf[:port], conf[:db])
114
118
  end
115
- if defined?(Redis::VERSION) && Redis::VERSION >= "2.0.0"
116
- def uri
117
- URI.parse format("redis://%s:%s/%s", @client.host, @client.port, @client.db)
118
- end
119
- else
120
- # Redis < 2.0.0
121
- class Client
122
- def uri
123
- URI.parse format("redis://%s:%s/%s", @host, @port, @db)
124
- end
125
- end
119
+
120
+ def uri
121
+ URI.parse @client.id
126
122
  end
127
123
  end
@@ -10,6 +10,11 @@ uri = URI.parse "redis://localhost/2"
10
10
  [uri.db, uri.host, uri.port]
11
11
  #=> [2, 'localhost', 6379]
12
12
 
13
+ ## Parsed URI can be accessed via conf hash
14
+ uri = URI.parse "redis://localhost:16739/2"
15
+ [uri.scheme, uri.conf]
16
+ #=> ['redis', {:host=>"localhost", :port=>16739, :db=>2, :ssl=>false}]
17
+
13
18
  ## Can parse a key name
14
19
  uri = URI.parse "redis://localhost/2/v1:arbitrary:key"
15
20
  [uri.key, uri.db, uri.host, uri.port]
@@ -26,3 +31,8 @@ uri = URI.parse "redis://localhost/2/v1:arbitrary:key"
26
31
  uri.key = "v2:arbitrary:key"
27
32
  uri.to_s
28
33
  #=> 'redis://localhost/2/v2:arbitrary:key'
34
+
35
+ ## Support rediss
36
+ uri = URI.parse "rediss://localhost"
37
+ [uri.scheme, uri.conf]
38
+ #=> ["rediss", {:host=>"localhost", :port=>6379, :db=>0, :ssl=>true}]
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - delano
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-21 00:00:00.000000000 Z
11
+ date: 2024-06-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: 'URI-Redis: support for parsing Redis URIs like redis://host:port/dbindex'
13
+ description: 'URI-Redis: support for parsing Redis URIs like redis://host:port/dbindex/key'
14
14
  email:
15
15
  - gems@solutious.com
16
16
  executables: []