Skip to content

Commit

Permalink
Docs and tests around Valkey
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Apr 26, 2024
1 parent 451e559 commit f63868f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
![dalle](https://user-images.githubusercontent.com/3890250/208236010-a89acc2a-ac79-44ca-9413-c1fa7c664ffe.jpg)

Redix is a [Redis][redis] client written in pure Elixir with focus on speed, correctness, and resiliency (that is, being able to automatically reconnect to Redis in case of network errors).
Redix is a [Redis][redis] and [Valkey][valkey] client written in pure Elixir with focus on speed, correctness, and resiliency (that is, being able to automatically reconnect to Redis in case of network errors).

This README refers to the main branch of Redix, not the latest released version on Hex. Make sure to check [the documentation][docs] for the version you're using.

Expand Down Expand Up @@ -153,3 +153,4 @@ Redix is released under the MIT license. See the [license file](LICENSE.txt).
[docker]: https://www.docker.com
[docker-compose]: https://docs.docker.com/compose/
[redis-terminology-issue]: https://github.com/antirez/redis/issues/5335
[valkey]: https://valkey.io/
9 changes: 8 additions & 1 deletion lib/redix.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Redix do
@moduledoc """
This module provides the main API to interface with Redis.
This module provides the main API to interface with [Redis](http://redis.io) and
[Valkey](https://valkey.io/).
## Overview
Expand Down Expand Up @@ -195,13 +196,19 @@ defmodule Redix do
* `redis://:secret@localhost:6397`
* `redis://username:secret@localhost:6397`
* `redis://example.com:6380/1`
* `rediss://example.com:6380/1` (for SSL connections)
* `valkey://example.com:6380/1` (for [Valkey](https://valkey.io/) connections)
The only mandatory thing when using URIs is the host. All other elements are optional
and their default value can be found in the "Options" section below.
In earlier versions of Redix, the username in the URI was ignored. Redis 6 introduced [ACL
support](https://redis.io/topics/acl). Now, Redix supports usernames as well.
> #### Valkey {: .info}
>
> The `valkey://` schema is supported since Redix v1.5.0.
## Options
The following options can be used to specify the connection:
Expand Down
7 changes: 6 additions & 1 deletion lib/redix/uri.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ defmodule Redix.URI do
redis://[username:password@]host[:port][/db]
> #### Valkey {: .tip}
>
> URIs also work with [Valkey](https://valkey.io/), a Redis-compatible in-memory key-value
> store. Use `valkey://` as the scheme instead of `redis://`.
## Examples
iex> Redix.URI.to_start_options("redis://example.com")
Expand All @@ -27,7 +32,7 @@ defmodule Redix.URI do
%URI{host: host, port: port, scheme: scheme} = uri = URI.parse(uri)

unless scheme in ["redis", "rediss", "valkey"] do
raise ArgumentError, "expected scheme to be redis://, valkey:// or rediss://, got: #{scheme}://"
raise ArgumentError, "expected scheme to be redis://, valkey://, or rediss://, got: #{scheme}://"
end

{username, password} = username_and_password(uri)
Expand Down
11 changes: 10 additions & 1 deletion test/redix/uri_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Redix.URITest do

describe "to_start_options/1" do
test "invalid scheme" do
message = "expected scheme to be redis:// or rediss://, got: foo://"
message = "expected scheme to be redis://, valkey://, or rediss://, got: foo://"

assert_raise ArgumentError, message, fn ->
to_start_options("foo://example.com")
Expand Down Expand Up @@ -88,5 +88,14 @@ defmodule Redix.URITest do
assert is_nil(opts[:database])
assert is_nil(opts[:password])
end

test "accepts valkey scheme" do
opts = to_start_options("valkey://example.com")
assert opts[:host] == "example.com"
assert is_nil(opts[:ssl])
assert is_nil(opts[:port])
assert is_nil(opts[:database])
assert is_nil(opts[:password])
end
end
end

0 comments on commit f63868f

Please sign in to comment.