Skip to content

Commit 7bc182f

Browse files
authored
Node redis (#2)
* feat: add Redis module with configuration options and service implementation - Introduced a new Redis module with dynamic configuration capabilities. - Added Redis service for managing Redis client connections. - Updated README and package.json to reflect changes in dependencies and installation instructions. - Created .editorconfig for consistent coding styles across the project. * feat: initialize NestJS Redis example project * chore: update NestJS and Redis dependencies, add examples to workspace * feat: enhance NestJS Redis example with configuration and delete functionality * fix: improve async options provider by using nullish coalescing and ensuring proper async handling * docs: add node-redis acknowledgment to README * test: add comprehensive Redis service tests for connection * feat: add Redis cluster support and enhance Redis service functionality * feat: enhance Docker Compose configuration for Redis with cluster and sentinel support * refactor: update ESLint configuration and enhance RedisService with cluster mode checks * fix: correct type casting for Redis cluster return value in createRedisClient function * chore: add directory field to node-redis package.json for improved repository structure * chore: bump version for ioredis and node-redis packages to 11.0.1 * docs: update installation instructions in README for @nestjs-labs/nestjs-ioredis package
1 parent 98e618d commit 7bc182f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6300
-2034
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 2
10+
11+
[*.{js,jsx,ts,tsx,json,md}]
12+
indent_style = space
13+
indent_size = 2
14+
15+
[*.{yml,yaml}]
16+
indent_style = space
17+
indent_size = 2

.github/workflows/testing.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ jobs:
2828
uses: hoverkraft-tech/compose-action@v2.0.2
2929
with:
3030
compose-file: './compose.yaml'
31+
compose-flags: '--profile cluster'
3132
up-flags: '-d'
3233
down-flags: '-v'
33-
- run: docker compose exec cluster-m1 redis-cli -a mycluster --cluster create 127.0.0.1:7380 127.0.0.1:7381 127.0.0.1:7382 --cluster-yes
3434
- run: pnpm install --frozen-lockfile
3535
- run: pnpm -F "@nestjs-labs/nestjs-redis" run lint
3636
- run: pnpm -F "@nestjs-labs/nestjs-redis" run test
37-
- run: pnpm -F "@nestjs-labs/nestjs-redis" run test:e2e
37+
# - run: pnpm -F "@nestjs-labs/nestjs-redis" run test:e2e

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.DS_Store
2+
.idea
3+
14
# Logs
25
logs
36
*.log
@@ -127,4 +130,4 @@ dist
127130
.yarn/unplugged
128131
.yarn/build-state.yml
129132
.yarn/install-state.gz
130-
.pnp.*
133+
.pnp.*

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ If you prefre [node-redis](https://github.com/redis/node-redis), check out [this
8787

8888
```sh
8989
# with npm
90-
npm install @nestjs-labs/nestjs-redis ioredis
90+
npm install @nestjs-labs/nestjs-redis redis
9191
# with yarn
92-
yarn add @nestjs-labs/nestjs-redis ioredis
92+
yarn add @nestjs-labs/nestjs-redis redis
9393
# with pnpm
94-
pnpm add @nestjs-labs/nestjs-redis ioredis
94+
pnpm add @nestjs-labs/nestjs-redis redis
9595
```
9696

9797
## Usage
@@ -239,6 +239,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
239239

240240
## Acknowledgments
241241

242+
- [node-redis](https://github.com/redis/node-redis)
242243
- [Full-Featured Redis Client - ioredis](https://github.com/luin/ioredis)
243244
- [Official Redis Documentation](https://redis.io/)
244245
- [Official Redis Docker Image](https://hub.docker.com/_/redis)

compose.yaml

Lines changed: 103 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,107 @@
1-
# sudo docker compose exec cluster-m1 redis-cli -a mycluster --cluster create 127.0.0.1:7380 127.0.0.1:7381 127.0.0.1:7382 --cluster-yes
1+
---
2+
# image tag 8.0-RC2-pre is the one matching the 8.0 GA release
3+
x-client-libs-stack-image: &client-libs-stack-image
4+
image: 'redislabs/client-libs-test:${CLIENT_LIBS_TEST_STACK_IMAGE_TAG:-8.0.2}'
5+
6+
x-client-libs-image: &client-libs-image
7+
image: 'redislabs/client-libs-test:${CLIENT_LIBS_TEST_IMAGE_TAG:-8.0.2}'
28

39
services:
410
redis:
5-
image: redis/redis-stack-server:latest
6-
network_mode: host
11+
<<: *client-libs-image
12+
container_name: redis-standalone
13+
environment:
14+
- TLS_ENABLED=yes
15+
- REDIS_CLUSTER=no
16+
- PORT=6379
17+
- TLS_PORT=6666
18+
command: ${REDIS_EXTRA_ARGS:---enable-debug-command yes --enable-module-command yes --tls-auth-clients optional --save ""}
19+
ports:
20+
- 6379:6379
21+
- 6666:6666 # TLS port
22+
volumes:
23+
- './dockers/standalone:/redis/work'
24+
profiles:
25+
- standalone
26+
- sentinel
27+
- replica
28+
- all-stack
29+
- all
30+
31+
replica:
32+
<<: *client-libs-image
33+
container_name: redis-replica
34+
depends_on:
35+
- redis
36+
environment:
37+
- TLS_ENABLED=no
38+
- REDIS_CLUSTER=no
39+
- PORT=6380
40+
command: ${REDIS_EXTRA_ARGS:---enable-debug-command yes --replicaof redis 6379 --protected-mode no --save ""}
41+
ports:
42+
- 6380:6380
43+
volumes:
44+
- './dockers/replica:/redis/work'
45+
profiles:
46+
- replica
47+
- all-stack
48+
- all
49+
50+
cluster:
51+
<<: *client-libs-image
52+
container_name: redis-cluster
53+
environment:
54+
- REDIS_CLUSTER=yes
55+
- NODES=6
56+
- REPLICAS=1
57+
- TLS_ENABLED=yes
58+
- PORT=16379
59+
- TLS_PORT=27379
60+
command: ${REDIS_EXTRA_ARGS:---enable-debug-command yes --enable-module-command yes --tls-auth-clients optional --save ""}
61+
ports:
62+
- '16379-16384:16379-16384'
63+
- '27379-27384:27379-27384'
64+
volumes:
65+
- './dockers/cluster:/redis/work'
66+
profiles:
67+
- cluster
68+
- all-stack
69+
- all
70+
71+
sentinel:
72+
<<: *client-libs-image
73+
container_name: redis-sentinel
74+
depends_on:
75+
- redis
76+
environment:
77+
- REDIS_CLUSTER=no
78+
- NODES=3
79+
- PORT=26379
80+
command: ${REDIS_EXTRA_ARGS:---sentinel}
81+
ports:
82+
- 26379:26379
83+
- 26380:26380
84+
- 26381:26381
85+
volumes:
86+
- './dockers/sentinel.conf:/redis/config-default/redis.conf'
87+
- './dockers/sentinel:/redis/work'
88+
profiles:
89+
- sentinel
90+
- all-stack
91+
- all
92+
93+
redis-stack:
94+
<<: *client-libs-stack-image
95+
container_name: redis-stack
796
environment:
8-
- 'REDIS_ARGS=--port 6380 --requirepass myredis --appendonly yes'
9-
cluster-m1:
10-
image: redis:latest
11-
network_mode: host
12-
command: 'redis-server --port 7380 --requirepass mycluster --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes'
13-
cluster-m2:
14-
image: redis:latest
15-
network_mode: host
16-
command: 'redis-server --port 7381 --requirepass mycluster --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes'
17-
cluster-m3:
18-
image: redis:latest
19-
network_mode: host
20-
command: 'redis-server --port 7382 --requirepass mycluster --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes'
97+
- REDIS_CLUSTER=no
98+
- PORT=6379
99+
command: ${REDIS_EXTRA_ARGS:---enable-debug-command yes --enable-module-command yes --save ""}
100+
ports:
101+
- 6479:6379
102+
volumes:
103+
- './dockers/redis-stack:/redis/work'
104+
profiles:
105+
- standalone
106+
- all-stack
107+
- all

dockers/sentinel.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sentinel resolve-hostnames yes
2+
sentinel monitor redis-py-test redis 6379 2
3+
sentinel down-after-milliseconds redis-py-test 5000
4+
sentinel failover-timeout redis-py-test 60000
5+
sentinel parallel-syncs redis-py-test 1

eslint.config.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export default tseslint.config(
1111
ignores: ['packages/global.d.ts', '**/dist/', '**/*.mjs']
1212
},
1313
eslint.configs.recommended,
14-
tseslint.configs.recommendedTypeChecked,
15-
tseslint.configs.stylisticTypeChecked,
14+
...tseslint.configs.recommendedTypeChecked,
15+
...tseslint.configs.stylisticTypeChecked,
1616
{
1717
files: jestFiles,
1818
...jest.configs['flat/recommended'],
@@ -27,7 +27,14 @@ export default tseslint.config(
2727
globals: globals.jest
2828
}
2929
},
30-
eslintPluginPrettierRecommended,
30+
{
31+
...eslintPluginPrettierRecommended,
32+
rules: {
33+
'prettier/prettier': 'off',
34+
'arrow-parens': ['error', 'always'],
35+
'@typescript-eslint/no-base-to-string': 'off'
36+
}
37+
},
3138
{
3239
linterOptions: {
3340
reportUnusedDisableDirectives: 'error'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<p align="center">
2+
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
3+
</p>
4+
5+
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6+
[circleci-url]: https://circleci.com/gh/nestjs/nest
7+
8+
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
9+
<p align="center">
10+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13+
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14+
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
15+
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
16+
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
17+
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
18+
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
19+
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
20+
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
21+
</p>
22+
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
23+
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
24+
25+
## Description
26+
27+
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
28+
29+
## Project setup
30+
31+
```bash
32+
$ pnpm install
33+
```
34+
35+
## Compile and run the project
36+
37+
```bash
38+
# development
39+
$ pnpm run start
40+
41+
# watch mode
42+
$ pnpm run start:dev
43+
44+
# production mode
45+
$ pnpm run start:prod
46+
```
47+
48+
## Run tests
49+
50+
```bash
51+
# unit tests
52+
$ pnpm run test
53+
54+
# e2e tests
55+
$ pnpm run test:e2e
56+
57+
# test coverage
58+
$ pnpm run test:cov
59+
```
60+
61+
## Deployment
62+
63+
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.
64+
65+
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
66+
67+
```bash
68+
$ pnpm install -g mau
69+
$ mau deploy
70+
```
71+
72+
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
73+
74+
## Resources
75+
76+
Check out a few resources that may come in handy when working with NestJS:
77+
78+
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
79+
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
80+
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
81+
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
82+
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
83+
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
84+
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
85+
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
86+
87+
## Support
88+
89+
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
90+
91+
## Stay in touch
92+
93+
- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
94+
- Website - [https://nestjs.com](https://nestjs.com/)
95+
- Twitter - [@nestframework](https://twitter.com/nestframework)
96+
97+
## License
98+
99+
Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @ts-check
2+
import eslint from '@eslint/js';
3+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
4+
import globals from 'globals';
5+
import tseslint from 'typescript-eslint';
6+
7+
export default tseslint.config(
8+
{
9+
ignores: ['eslint.config.mjs'],
10+
},
11+
eslint.configs.recommended,
12+
...tseslint.configs.recommendedTypeChecked,
13+
eslintPluginPrettierRecommended,
14+
{
15+
languageOptions: {
16+
globals: {
17+
...globals.node,
18+
...globals.jest,
19+
},
20+
sourceType: 'commonjs',
21+
parserOptions: {
22+
projectService: true,
23+
tsconfigRootDir: import.meta.dirname,
24+
},
25+
},
26+
},
27+
{
28+
rules: {
29+
'@typescript-eslint/no-explicit-any': 'off',
30+
'@typescript-eslint/no-floating-promises': 'warn',
31+
'@typescript-eslint/no-unsafe-argument': 'warn',
32+
},
33+
},
34+
);

0 commit comments

Comments
 (0)