Skip to content

Commit 509ea5e

Browse files
machtyioquatix
authored andcommitted
Add REDIS_URL / SSL endpoint example to README
1 parent 8926c20 commit 509ea5e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,37 @@ ensure
2727
end
2828
```
2929

30+
### Connecting to Redis SSL Endpoint
31+
32+
This example demonstrates parsing an environment variable with a `redis://` or SSL `rediss://` scheme, and demonstrates how you can specify SSL parameters on the SSLContext object.
33+
34+
``` ruby
35+
require 'async/redis'
36+
37+
def make_redis_endpoint(uri)
38+
tcp_endpoint = Async::IO::Endpoint.tcp(uri.hostname, uri.port)
39+
case uri.scheme
40+
when 'redis'
41+
tcp_endpoint
42+
when 'rediss'
43+
ssl_context = OpenSSL::SSL::SSLContext.new
44+
ssl_context.set_params(
45+
ca_file: "/path/to/ca.crt",
46+
cert: OpenSSL::X509::Certificate.new(File.read("client.crt")),
47+
key: OpenSSL::PKey::RSA.new(File.read("client.key")),
48+
)
49+
Async::IO::SSLEndpoint.new(tcp_endpoint, ssl_context: ssl_context)
50+
else
51+
raise ArgumentError
52+
end
53+
end
54+
55+
endpoint = make_redis_endpoint(URI(ENV['REDIS_URL']))
56+
client = Async::Redis::Client.new(endpoint)
57+
58+
# ...
59+
```
60+
3061
### Variables
3162

3263
``` ruby

0 commit comments

Comments
 (0)