From 509ea5ee482e972b8db6e17b8dcdd5977ceec791 Mon Sep 17 00:00:00 2001 From: machty Date: Thu, 28 Jan 2021 17:33:34 -0500 Subject: [PATCH] Add REDIS_URL / SSL endpoint example to README --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index 64616bf..b171cb2 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,37 @@ ensure end ``` +### Connecting to Redis SSL Endpoint + +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. + +``` ruby +require 'async/redis' + +def make_redis_endpoint(uri) + tcp_endpoint = Async::IO::Endpoint.tcp(uri.hostname, uri.port) + case uri.scheme + when 'redis' + tcp_endpoint + when 'rediss' + ssl_context = OpenSSL::SSL::SSLContext.new + ssl_context.set_params( + ca_file: "/path/to/ca.crt", + cert: OpenSSL::X509::Certificate.new(File.read("client.crt")), + key: OpenSSL::PKey::RSA.new(File.read("client.key")), + ) + Async::IO::SSLEndpoint.new(tcp_endpoint, ssl_context: ssl_context) + else + raise ArgumentError + end +end + +endpoint = make_redis_endpoint(URI(ENV['REDIS_URL'])) +client = Async::Redis::Client.new(endpoint) + +# ... +``` + ### Variables ``` ruby