Skip to content

Commit

Permalink
[#65] Migrate adapter to Nebulex V3
Browse files Browse the repository at this point in the history
  • Loading branch information
cabol committed Dec 8, 2024
1 parent 9106372 commit dbe9e1a
Show file tree
Hide file tree
Showing 51 changed files with 2,741 additions and 2,413 deletions.
1 change: 1 addition & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ locals_without_parens = [
]

[
import_deps: [:nebulex],
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
line_length: 100,
locals_without_parens: locals_without_parens,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
nebulex_test:
name: >-
NebulexRedisAdapter Test (Elixir ${{ matrix.elixir }} / OTP ${{ matrix.otp }} /
Nebulex.Adapters.Redis Test (Elixir ${{ matrix.elixir }} / OTP ${{ matrix.otp }} /
OS ${{ matrix.os }})
runs-on: ${{ matrix.os }}

Expand Down
10 changes: 0 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v2.4.2](https://github.com/cabol/nebulex_redis_adapter/tree/v2.4.2) (2024-11-01)

[Full Changelog](https://github.com/cabol/nebulex_redis_adapter/compare/v2.4.1...v2.4.2)

**Closed issues:**

- `NebulexRedisAdapter.RedisCluster.Keyslot` incorrectly computes slot for
hash tags.
[#64](https://github.com/cabol/nebulex_redis_adapter/issues/64)

## [v2.4.1](https://github.com/cabol/nebulex_redis_adapter/tree/v2.4.1) (2024-09-01)

[Full Changelog](https://github.com/cabol/nebulex_redis_adapter/compare/v2.4.0...v2.4.1)
Expand Down
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NebulexRedisAdapter
# Nebulex.Adapters.Redis
> Nebulex adapter for Redis (including [Redis Cluster][redis_cluster] support).
![CI](https://github.com/cabol/nebulex_redis_adapter/workflows/CI/badge.svg)
Expand All @@ -15,7 +15,7 @@ next sections.
See also [online documentation][nbx_redis_adapter]
and [Redis cache example][nbx_redis_example].

[nbx_redis_adapter]: http://hexdocs.pm/nebulex_redis_adapter/NebulexRedisAdapter.html
[nbx_redis_adapter]: http://hexdocs.pm/nebulex_redis_adapter/Nebulex.Adapters.Redis.html
[nbx_redis_example]: https://github.com/cabol/nebulex_examples/tree/master/redis_cache
[redis_cluster]: https://redis.io/topics/cluster-tutorial

Expand Down Expand Up @@ -51,7 +51,7 @@ After installing, we can define our cache to use Redis adapter as follows:
defmodule MyApp.RedisCache do
use Nebulex.Cache,
otp_app: :my_app,
adapter: NebulexRedisAdapter
adapter: Nebulex.Adapters.Redis
end
```

Expand All @@ -69,15 +69,15 @@ config :my_app, MyApp.RedisCache,

Since this adapter is implemented by means of `Redix`, it inherits the same
options, including regular Redis options and connection options as well. For
more information about the options, please check out `NebulexRedisAdapter`
more information about the options, please check out `Nebulex.Adapters.Redis`
module and also [Redix](https://github.com/whatyouhide/redix).

See also [Redis cache example][nbx_redis_example].

## Distributed Caching

There are different ways to support distributed caching when using
**NebulexRedisAdapter**.
**Nebulex.Adapters.Redis**.

### Redis Cluster

Expand All @@ -95,7 +95,7 @@ Then we can define our cache which will use **Redis Cluster**:
defmodule MyApp.RedisClusterCache do
use Nebulex.Cache,
otp_app: :my_app,
adapter: NebulexRedisAdapter
adapter: Nebulex.Adapters.Redis
end
```

Expand Down Expand Up @@ -127,11 +127,11 @@ The pool of connections to the different master nodes is automatically
configured by the adapter once it gets the cluster slots info.

> This one could be the easiest and recommended way for distributed caching
using Redis and **NebulexRedisAdapter**.
using Redis and **Nebulex.Adapters.Redis**.

### Client-side Cluster based on Sharding

**NebulexRedisAdapter** also brings with a simple client-side cluster
**Nebulex.Adapters.Redis** also brings with a simple client-side cluster
implementation based on Sharding distribution model.

We define our cache normally:
Expand All @@ -140,7 +140,7 @@ We define our cache normally:
defmodule MyApp.ClusteredCache do
use Nebulex.Cache,
otp_app: :my_app,
adapter: NebulexRedisAdapter
adapter: Nebulex.Adapters.Redis
end
```

Expand Down Expand Up @@ -182,9 +182,9 @@ config :my_app, MyApp.ClusteredCache,
]
```

By default, the adapter uses `NebulexRedisAdapter.ClientCluster.Keyslot` for the
keyslot. Besides, if `:jchash` is defined as dependency, the adapter will use
consistent-hashing automatically.
By default, the adapter uses `Nebulex.Adapters.Redis.ClientSideCluster.Keyslot`
for the keyslot. Besides, if `:jchash` is defined as dependency, the adapter
will use consistent-hashing automatically.

> **NOTE:** It is highly recommended to define the `:jchash` dependency
when using the adapter in `:client_side_cluster` mode.
Expand Down Expand Up @@ -224,28 +224,28 @@ config :my_app, MyApp.ClusteredCache,
### Using `Nebulex.Adapters.Partitioned`

Another simple option is to use the `Nebulex.Adapters.Partitioned` and set as
local cache the `NebulexRedisAdapter`. The idea here is each Elixir node running
the distributed cache (`Nebulex.Adapters.Partitioned`) will have as local
backend or cache a Redis instance (handled by `NebulexRedisAdapter`).
local cache the `Nebulex.Adapters.Redis`. The idea here is each Elixir node
running the distributed cache (`Nebulex.Adapters.Partitioned`) will have as
local backend or cache a Redis instance (handled by `Nebulex.Adapters.Redis`).


This example shows how the setup a distributed cache using
`Nebulex.Adapters.Partitioned` and `NebulexRedisAdapter`:
`Nebulex.Adapters.Partitioned` and `Nebulex.Adapters.Redis`:

```elixir
defmodule MyApp.DistributedCache do
use Nebulex.Cache,
otp_app: :my_app,
adapter: Nebulex.Adapters.Partitioned,
primary_storage_adapter: NebulexRedisAdapter
primary_storage_adapter: Nebulex.Adapters.Redis
end
```

### Using a Redis Proxy

The other option is to use a proxy, like [Envoy proxy][envoy] or
[Twemproxy][twemproxy] on top of Redis. In this case, the proxy does the
distribution work, and from the adparter's side (**NebulexRedisAdapter**),
distribution work, and from the adparter's side (**Nebulex.Adapters.Redis**),
it would be only configuration. Instead of connect the adapter against the
Redis nodes, we connect it against the proxy nodes, this means, in the config,
we setup the pool with the host and port pointing to the proxy.
Expand All @@ -255,13 +255,13 @@ we setup the pool with the host and port pointing to the proxy.

## Running Redis commands and/or pipelines

Since `NebulexRedisAdapter` works on top of `Redix` and provides features like
connection pools and "Redis Cluster" support, it may be seen also as a sort of
Redis client, but it is meant to be used mainly with the Nebulex cache API.
However, Redis API is quite extensive and there are a lot of useful commands
we may want to run taking advantage of the `NebulexRedisAdapter` features.
Therefore, the adapter injects two additional/extended functions to the
defined cache: `command!/2` and `pipeline!/2`.
Since `Nebulex.Adapters.Redis` works on top of `Redix` and provides features
like connection pools and "Redis Cluster" support, it may be seen also as a
sort of Redis client, but it is meant to be used mainly with the Nebulex cache
API. However, Redis API is quite extensive and there are a lot of useful
commands we may want to run taking advantage of the `Nebulex.Adapters.Redis`
features. Therefore, the adapter injects two additional/extended functions
to the defined cache: `command!/2` and `pipeline!/2`.

```elixir
iex> MyCache.command!(["LPUSH", "mylist", "world"], key: "mylist")
Expand All @@ -287,8 +287,8 @@ you have to pass the cache name explicitly.

## Testing

To run the **NebulexRedisAdapter** tests you will have to have Redis running
locally. **NebulexRedisAdapter** requires a complex setup for running tests
To run the **Nebulex.Adapters.Redis** tests you will have to have Redis running
locally. **Nebulex.Adapters.Redis** requires a complex setup for running tests
(since it needs a few instances running, for standalone, cluster and Redis
Cluster). For this reason, there is a [docker-compose.yml](docker-compose.yml)
file in the repo so that you can use [Docker][docker] and
Expand All @@ -302,7 +302,7 @@ $ docker-compose up
[docker]: https://www.docker.com/
[docker_compose]: https://docs.docker.com/compose/

Since `NebulexRedisAdapter` uses the support modules and shared tests
Since `Nebulex.Adapters.Redis` uses the support modules and shared tests
from `Nebulex` and by default its test folder is not included in the Hex
dependency, the following steps are required for running the tests.

Expand Down Expand Up @@ -373,4 +373,4 @@ all checks run successfully.

Copyright (c) 2018, Carlos Bolaños.

NebulexRedisAdapter source code is licensed under the [MIT License](LICENSE).
Nebulex.Adapters.Redis source code is licensed under the [MIT License](LICENSE).
10 changes: 5 additions & 5 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Config

# Standalone mode
config :nebulex_redis_adapter, NebulexRedisAdapter.TestCache.Standalone,
config :nebulex_redis_adapter, Nebulex.Adapters.Redis.TestCache.Standalone,
conn_opts: [
host: "127.0.0.1",
port: 6379
]

# Cluster mode
config :nebulex_redis_adapter, NebulexRedisAdapter.TestCache.ClientCluster,
# Client-side cluster mode
config :nebulex_redis_adapter, Nebulex.Adapters.Redis.TestCache.ClientSideCluster,
mode: :client_side_cluster,
client_side_cluster: [
nodes: [
Expand All @@ -34,7 +34,7 @@ config :nebulex_redis_adapter, NebulexRedisAdapter.TestCache.ClientCluster,
]

# Redis Cluster mode (with Redis >= 7)
config :nebulex_redis_adapter, NebulexRedisAdapter.TestCache.RedisCluster,
config :nebulex_redis_adapter, Nebulex.Adapters.Redis.TestCache.RedisCluster,
mode: :redis_cluster,
redis_cluster: [
# Configuration endpoints
Expand All @@ -51,7 +51,7 @@ config :nebulex_redis_adapter, NebulexRedisAdapter.TestCache.RedisCluster,
]

# Redis Cluster mode with errors
config :nebulex_redis_adapter, NebulexRedisAdapter.TestCache.RedisClusterConnError,
config :nebulex_redis_adapter, Nebulex.Adapters.Redis.TestCache.RedisClusterConnError,
mode: :redis_cluster,
pool_size: 2,
redis_cluster: [
Expand Down
8 changes: 5 additions & 3 deletions coveralls.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"skip_files": [
"lib/nebulex_redis_adapter/exceptions.ex",
"lib/nebulex_redis_adapter/helpers.ex",
"lib/nebulex_redis_adapter/serializer.ex",
"lib/nebulex/adapters/redis/helpers.ex",
"lib/nebulex/adapters/redis/serializer.ex",
"lib/nebulex/adapters/redis/serializer/serializable.ex",
"lib/nebulex/adapters/redis/options.ex",
"lib/nebulex/adapters/redis/error_formatter.ex",
"test/*"
],
"coverage_options": {
Expand Down
Loading

0 comments on commit dbe9e1a

Please sign in to comment.