uri-valkey 1.4.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6af4f80b4b8f3a5a8d7bc33469965c8a1dcd07d6bc52a71d3cd8627e1315d6c2
4
+ data.tar.gz: a4e53b636f1dd887d0319d84a1137e0f49e6e4aefa9babe03fe3c9e4e938a4ae
5
+ SHA512:
6
+ metadata.gz: 2b65e694ad0a2954c02e1fad115f0153647a39314d52f5cf95af8fa19b9e081fe1284bc4969c0d51443348ae4b6c613a721c0117fdcb7989bfc4dbc1e5787c21
7
+ data.tar.gz: f81126f4e47f6b690217b1f3d408e504853586ac01e0fbbd8d4df50fbf3ce6fdee718a20fa79d5e1f197448fa75a96cae54ffc7c91e40cec9967ee2e76fa1979
data/CHANGES.txt ADDED
@@ -0,0 +1,76 @@
1
+ URI-Redis, CHANGES
2
+
3
+ #### 1.3.0 (2024-06-15) ###############################
4
+
5
+ * Add support for rediss scheme (thanks @sebastien-coavoux).
6
+
7
+ #### 1.2.0 (2024-05-20) ###############################
8
+
9
+ * Fix for Ruby <= 3.0 `register_scheme` error.
10
+
11
+
12
+ #### 1.1.2 (2024-05-02) ###############################
13
+
14
+ * Same functionality as the now yanked 1.1.1 with
15
+ updated metadata, including:
16
+ * Remove minimum ruby version from Gemfile
17
+ * Corrected Gemfile.lock file with latest deps
18
+ * Improved Github Action workflow.
19
+ * Fixes for Rubocop complaints.
20
+
21
+
22
+ #### 1.1.1 (2024-04-05) ###############################
23
+
24
+ ** Yanked May 2nd **
25
+
26
+ #### 1.1.0 (2024-04-04) ###############################
27
+
28
+ * Fix for frozen strings issue.
29
+ * Allow fow updated redis, tryouts releases.
30
+
31
+
32
+ #### 1.0.0 (2023-01-17) ###############################
33
+
34
+ * CHANGE: Just a version bump to 1.0 for a full
35
+ release. No code changes.
36
+
37
+
38
+ #### 1.0.0-RC2 (2023-01-16) ###########################
39
+
40
+ * FIXED: Harmonized ruby versions across gemspec,
41
+ code, and github action.
42
+
43
+
44
+ #### 1.0.0-RC1 (2023-01-16) ###########################
45
+
46
+ * CHANGE: Moderized gem
47
+ * ADDED: Only redis-4.1.0+ supported
48
+ * FIXED: Support URI v0.11
49
+ * See: https://github.com/delano/redis-dump/issues/33
50
+
51
+
52
+ #### 0.4.2 (2010-12-23) ###############################
53
+
54
+ # CHANGE: URI#conf enforces symbols as keys
55
+ * ADDED: URI#conf parses query string
56
+
57
+
58
+ #### 0.4.1 (2010-11-16) ###############################
59
+
60
+ * FIXED: Nil error in URI::Redis#key
61
+
62
+ #### 0.4.0 (2010-11-15) ###############################
63
+
64
+ * ADDED: Support for keys in the path
65
+ * CHANGE: Updated tryouts to 2.0
66
+
67
+
68
+ #### 0.3.0 (2010-06-03) ###############################
69
+
70
+ * CHANGE: Redis::Client.uri is now Redis.uri
71
+ * ADDED: Support for redis-2.0.0
72
+
73
+
74
+ #### 0.2.0 (2010-05-30) ###############################
75
+
76
+ * Initial public release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) delano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # URI-Valkey
2
+
3
+ Creates URI objects for Valkey URLs, with support for parsing connection strings and extracting configuration parameters.
4
+
5
+ ## Supported URI Formats
6
+
7
+ valkey://host:port/dbindex
8
+ valkeys://host:port/dbindex # SSL
9
+ redis://host:port/dbindex # Cross-scheme compatibility
10
+ rediss://host:port/dbindex # Cross-scheme compatibility (SSL)
11
+
12
+ ## Installation
13
+
14
+ * `gem install uri-valkey`
15
+ * `git clone git@github.com:delano/uri-valkey.git`
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ require 'uri-valkey' # or require 'uri_valkey'
21
+
22
+ conf = URI.parse 'valkey://localhost:6379/0'
23
+ conf.scheme # => "valkey"
24
+ conf.host # => "localhost"
25
+ conf.port # => 6379
26
+ conf.db # => 0
27
+ conf.to_s # => "valkey://localhost:6379/0"
28
+
29
+ # Access configuration hash
30
+ conf.conf # => {:host=>"localhost", :port=>6379, :db=>0, :ssl=>false}
31
+ ```
32
+
33
+ ### SSL Support
34
+
35
+ SSL is supported by using the `valkeys` scheme:
36
+
37
+ ```ruby
38
+ conf = URI.parse 'valkeys://localhost:6379/0'
39
+ conf.scheme # => "valkeys"
40
+ conf.conf[:ssl] # => true
41
+ ```
42
+
43
+ ### Working with Keys
44
+
45
+ The URI class supports parsing and manipulating Valkey keys:
46
+
47
+ ```ruby
48
+ uri = URI.parse 'valkey://localhost:6379/2/mykey:namespace'
49
+ uri.db # => 2
50
+ uri.key # => "mykey:namespace"
51
+
52
+ # Modify the key
53
+ uri.key = 'newkey:value'
54
+ uri.to_s # => "valkey://localhost:6379/2/newkey:value"
55
+
56
+ # Modify the database
57
+ uri.db = 5
58
+ uri.to_s # => "valkey://localhost:6379/5/newkey:value"
59
+ ```
60
+
61
+ ### Building URIs
62
+
63
+ ```ruby
64
+ uri = URI::Valkey.build(host: "localhost", port: 6379, db: 2, key: "v1:arbitrary:key")
65
+ uri.to_s # => "valkey://localhost:6379/2/v1:arbitrary:key"
66
+ ```
67
+
68
+ ### Query Parameters
69
+
70
+ Query parameters are supported for additional configuration:
71
+
72
+ ```ruby
73
+ uri = URI.parse "valkey://127.0.0.1/6/?timeout=5&retries=3"
74
+ uri.conf # => {:db=>6, :timeout=>5, :retries=>"3", :host=>"127.0.0.1", :port=>6379, :ssl=>false}
75
+ ```
76
+
77
+ ## Cross-Scheme Compatibility
78
+
79
+ Both gems support each other's URL schemes for maximum flexibility:
80
+
81
+ ```ruby
82
+ # Valkey gem can parse Redis URLs
83
+ redis_uri = URI.parse 'redis://localhost:6379/0'
84
+ redis_uri.scheme # => "redis"
85
+ redis_uri.conf # => {:host=>"localhost", :port=>6379, :db=>0, :ssl=>false}
86
+
87
+ # SSL schemes work cross-platform
88
+ ssl_uri = URI.parse 'rediss://localhost:6379/0'
89
+ ssl_uri.conf[:ssl] # => true
90
+ ```
91
+
92
+ ## URI-Redis
93
+
94
+ A `uri-redis` gem is also available with identical functionality for Redis URLs, including support for `valkey://` and `valkeys://` schemes:
95
+
96
+ ```ruby
97
+ require 'uri-redis'
98
+
99
+ conf = URI.parse 'redis://localhost:6379/0'
100
+ conf.scheme # => "redis"
101
+ conf.conf # => {:host=>"localhost", :port=>6379, :db=>0, :ssl=>false}
102
+ ```
103
+
104
+ ### Redis Client Integration
105
+
106
+ If you have the `redis` gem installed, URI-Redis provides a refinement to add URI support directly to Redis client instances:
107
+
108
+ ```ruby
109
+ require 'uri-redis'
110
+
111
+ # Enable the refinement in your scope
112
+ using RedisURIRefinement
113
+
114
+ redis = Redis.new(url: 'redis://localhost:6379/2')
115
+ redis.uri # Returns URI object for the Redis client's connection
116
+
117
+ # Class method for generating URIs from configuration
118
+ Redis.uri(host: 'localhost', port: 6379, db: 2, ssl: true)
119
+ # => URI object for "rediss://localhost:6379/2"
120
+ ```
121
+
122
+ **Note:** The refinement is only available when the `redis` gem is loaded and only works within scopes where `using RedisURIRefinement` has been called.
123
+
124
+ ## About
125
+
126
+ * [Github](https://github.com/delano/uri-valkey)
127
+
128
+ ## License
129
+
130
+ See LICENSE.txt
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'uri/generic'
5
+
6
+ module URI
7
+ # Shared module for Valkey-compatible database URI classes (Redis, Valkey, etc.)
8
+ # Provides common functionality for handling database URIs with database indices and key paths
9
+ module PerfectStrangers
10
+ DEFAULT_PORT = 6379
11
+ DEFAULT_DB = 0
12
+
13
+ def self.included(base)
14
+ base.extend(ClassMethods)
15
+ end
16
+
17
+ # Class methods for database URI classes
18
+ module ClassMethods
19
+ def build(args)
20
+ tmp = Util.make_components_hash(self, args)
21
+ super(tmp)
22
+ end
23
+ end
24
+
25
+ def request_uri
26
+ path_query
27
+ end
28
+
29
+ def key
30
+ return if path.nil?
31
+
32
+ self.path ||= "/#{DEFAULT_DB}"
33
+ (self.path.split('/')[2..] || []).join('/')
34
+ end
35
+
36
+ def key=(val)
37
+ self.path = if val && !val.to_s.empty?
38
+ "/#{db}/#{val}"
39
+ else
40
+ "/#{db}"
41
+ end
42
+ end
43
+
44
+ def db
45
+ self.path ||= "/#{DEFAULT_DB}"
46
+ (self.path.split('/')[1] || DEFAULT_DB).to_i
47
+ end
48
+
49
+ def db=(val)
50
+ current_key = key
51
+ self.path = if current_key && !current_key.empty?
52
+ "/#{val}/#{current_key}"
53
+ else
54
+ "/#{val}"
55
+ end
56
+ end
57
+
58
+ def conf
59
+ hsh = {
60
+ host: host,
61
+ port: port,
62
+ db: db,
63
+ ssl: ssl_schemes.include?(scheme)
64
+ }.merge(parse_query(query))
65
+ hsh[:password] = password if password
66
+ hsh[:timeout] = hsh[:timeout].to_i if hsh.key?(:timeout)
67
+ hsh
68
+ end
69
+
70
+ def serverid
71
+ format('%s://%s:%s/%s', scheme, host, port, db)
72
+ end
73
+
74
+ private
75
+
76
+ # Override in including classes to define which schemes use SSL
77
+ def ssl_schemes
78
+ raise NotImplementedError, 'ssl_schemes must be implemented in including classes'
79
+ end
80
+
81
+ # Based on: https://github.com/chneukirchen/rack/blob/master/lib/rack/utils.rb
82
+ # which was originally based on Mongrel
83
+ def parse_query(query, delim = nil)
84
+ delim ||= '&;'
85
+ params = {}
86
+ (query || '').split(/[#{delim}] */n).each do |p|
87
+ k, v = p.split('=', 2).map { |str| str } # NOTE: uri_unescape
88
+ k = k.to_sym
89
+ if (cur = params[k])
90
+ if cur.instance_of?(Array)
91
+ params[k] << v
92
+ else
93
+ params[k] = [cur, v]
94
+ end
95
+ else
96
+ params[k] = v
97
+ end
98
+ end
99
+ params
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'uri/generic'
5
+
6
+ module URI
7
+ class Valkey < URI::Generic
8
+ VERSION = '1.4.0'
9
+ SUMMARY = 'A Ruby library for parsing, building and normalizing valkey URLs'
10
+ end
11
+ end
data/lib/uri/valkey.rb ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'uri/generic'
5
+
6
+ require_relative 'perfect_strangers'
7
+
8
+ # URI::Valkey - adds support for Valkey URIs to core.
9
+ module URI
10
+ # Valkey URI
11
+ #
12
+ # This is a subclass of URI::Generic and supports the following URI formats:
13
+ #
14
+ # valkey://host:port/dbindex
15
+ #
16
+ # @example
17
+ # uri = URI::Valkey.build(host: "localhost", port: 6379, db: 2, key: "v1:arbitrary:key")
18
+ # uri.to_s #=> "valkey://localhost:6379/2/v1:arbitrary:key"
19
+ #
20
+ # uri = URI::Valkey.build(host: "localhost", port: 6379, db: 2)
21
+ # uri.to_s #=> "valkey://localhost:6379/2"
22
+ class Valkey < URI::Generic
23
+ include PerfectStrangers
24
+
25
+ private
26
+
27
+ def ssl_schemes
28
+ %w[valkeys rediss]
29
+ end
30
+ end
31
+
32
+ if URI.respond_to?(:register_scheme)
33
+ URI.register_scheme 'VALKEY', Valkey unless URI.scheme_list.key?('VALKEY')
34
+ URI.register_scheme 'VALKEYS', Valkey unless URI.scheme_list.key?('VALKEYS')
35
+ # Cross-scheme support for Redis URLs
36
+ URI.register_scheme 'REDIS', Valkey unless URI.scheme_list.key?('REDIS')
37
+ URI.register_scheme 'REDISS', Valkey unless URI.scheme_list.key?('REDISS')
38
+ else
39
+ @@schemes['VALKEY'] = Valkey unless @@schemes.key?('VALKEY')
40
+ @@schemes['VALKEYS'] = Valkey unless @@schemes.key?('VALKEYS')
41
+ # Cross-scheme support for Redis URLs
42
+ @@schemes['REDIS'] = Valkey unless @@schemes.key?('REDIS')
43
+ @@schemes['REDISS'] = Valkey unless @@schemes.key?('REDISS')
44
+ end
45
+ end
data/lib/uri-valkey.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Compatibility shim for uri-valkey.rb
4
+ # This file maintains backward compatibility for code that requires 'uri-valkey'
5
+ require_relative 'uri/valkey'
data/lib/uri_valkey.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Compatibility shim for uri_valkey.rb
4
+ # This file maintains backward compatibility for code that requires 'uri_valkey'
5
+ require_relative 'uri/valkey'
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uri-valkey
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ platform: ruby
6
+ authors:
7
+ - delano
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: 'URI-Valkey: support for parsing Valkey URIs like valkey://host:port/dbindex/key'
13
+ email:
14
+ - gems@solutious.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - CHANGES.txt
20
+ - LICENSE.txt
21
+ - README.md
22
+ - lib/uri-valkey.rb
23
+ - lib/uri/perfect_strangers.rb
24
+ - lib/uri/valkey.rb
25
+ - lib/uri/valkey/version.rb
26
+ - lib/uri_valkey.rb
27
+ homepage: https://github.com/delano/uri-valkey
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ allowed_push_host: https://rubygems.org
32
+ homepage_uri: https://github.com/delano/uri-valkey
33
+ source_code_uri: https://github.com/delano/uri-valkey/
34
+ changelog_uri: https://github.com/delano/uri-valkey/blob/main/CHANGES.txt#L1
35
+ rubygems_mfa_required: 'true'
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.7.5
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.6.9
51
+ specification_version: 4
52
+ summary: 'URI-Valkey: support for parsing Valkey URIs'
53
+ test_files: []