Skip to content

Commit fa38a71

Browse files
authored
Merge pull request #8 from waterbustech/feat/redis-cluster
feat: use redis cluster
2 parents 96d2497 + 97d0640 commit fa38a71

File tree

8 files changed

+163
-57
lines changed

8 files changed

+163
-57
lines changed

Cargo.lock

Lines changed: 89 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ socketioxide = { version = "0.17.1", features = [
3535
"state",
3636
"msgpack",
3737
] }
38-
socketioxide-redis = "0.2.2"
38+
socketioxide-redis = { version = "0.2.2", features = ["redis-cluster"] }
3939
tokio = { version = "1.45.0", features = ["full"] }
4040
tokio-util = "0.7.15"
4141
tower = { version = "0.5.2", default-features = false }
@@ -91,7 +91,8 @@ tonic = "0.13.1"
9191
etcd-client = "0.15.0"
9292
sysinfo = "0.35.1"
9393
futures-util = "0.3.31"
94-
redis = "0.31.0"
94+
deadpool-redis = "0.22.0"
95+
redis = { version = "0.32.4", features = ["cluster"] }
9596
futures = "0.3.31"
9697
crossbeam = "0.8.4"
9798
mimalloc = "0.1.46"

crates/dispatcher/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ async-channel = { workspace = true }
1515
serde_json = { workspace = true }
1616
serde = { workspace = true }
1717
futures-util = { workspace = true }
18+
deadpool-redis = { workspace = true }
1819
redis = { workspace = true }

crates/dispatcher/src/dispatcher_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct DispatcherConfigs {
2424
pub group_id: String,
2525
pub dispatcher_port: u16,
2626
pub sfu_port: u16,
27-
pub redis_uri: String,
27+
pub redis_uris: Vec<String>,
2828
pub etcd_uri: String,
2929
pub sender: Sender<DispatcherCallback>,
3030
}
@@ -51,7 +51,7 @@ impl DispatcherManager {
5151
.unwrap();
5252

5353
let sfu_grpc_client = SfuGrpcClient::default();
54-
let cache_manager = CacheManager::new(configs.redis_uri);
54+
let cache_manager = CacheManager::new(configs.redis_uris);
5555

5656
Self {
5757
sfu_grpc_client,

crates/dispatcher/src/infrastructure/cache/cache_manager.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use redis::{Client, Commands};
1+
use redis::{Commands, cluster::ClusterClient};
22
use serde::{Deserialize, Serialize};
33
use std::sync::{Arc, Mutex};
44

@@ -21,14 +21,14 @@ impl CacheKey {
2121
}
2222
}
2323

24-
#[derive(Debug, Clone)]
24+
#[derive(Clone)]
2525
pub struct CacheManager {
26-
client: Arc<Mutex<Client>>,
26+
client: Arc<Mutex<ClusterClient>>,
2727
}
2828

2929
impl CacheManager {
30-
pub fn new(redis_uri: String) -> Self {
31-
let client = Client::open(redis_uri).unwrap();
30+
pub fn new(urls: Vec<String>) -> Self {
31+
let client = ClusterClient::new(urls).unwrap();
3232
Self {
3333
client: Arc::new(Mutex::new(client)),
3434
}

example.env

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1-
# APP
21
APP_PORT=5998
2+
CLIENT_SECRET_KEY=
3+
SERVER_SECRET_KEY=
4+
TLS_ENABLED=false
35

4-
# DB
5-
DATABASE_URI=postgresql://postgres:postgres@localhost:5432/mydatabase
6-
REDIS_URI=redis://localhost:6379
6+
DATABASE_URI=postgres://postgres:password@localhost:5432/database
77

8-
# AWS Configure
9-
AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID
10-
AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY
11-
AWS_REGION=ap-southeast-1
12-
AWS_S3_BUCKET_NAME=your-s3-bucket-name
8+
REDIS_URIS=redis://127.0.0.1:6379?protocol=resp3,redis://127.0.0.1:6380?protocol=resp3,redis://127.0.0.1:6381?protocol=resp3,redis://127.0.0.1:6382?protocol=resp3,redis://127.0.0.1:6383?protocol=resp3,redis://127.0.0.1:6384?protocol=resp3
139

14-
# JWT Configure
15-
AUTH_JWT_SECRET=your_jwt_secret
16-
AUTH_JWT_TOKEN_EXPIRES_IN=24h
17-
AUTH_REFRESH_SECRET=your_refresh_secret
18-
AUTH_REFRESH_TOKEN_EXPIRES_IN=3650d
10+
STORAGE_ACCOUNT_ID=
11+
STORAGE_ACCESS_KEY_ID=
12+
STORAGE_SECRET_ACCESS_KEY=
13+
STORAGE_REGION=auto
14+
STORAGE_BUCKET_NAME=
15+
STORAGE_ENDPOINT_URL=
16+
STORAGE_CUSTOM_DOMAIN=
17+
18+
AUTH_JWT_SECRET=
19+
AUTH_JWT_TOKEN_EXPIRES_IN=86400
20+
AUTH_REFRESH_SECRET=
21+
AUTH_REFRESH_TOKEN_EXPIRES_IN=31536000
1922

20-
# WebRTC
2123
PUBLIC_IP=
22-
PORT_MIN_UDP=19200
23-
PORT_MAX_UDP=19250
24+
PORT_MIN_UDP=19000
25+
PORT_MAX_UDP=60000
26+
27+
GROUP_ID=waterbus-group-1
28+
SFU_HOST=http://0.0.0.0
29+
SFU_PORT=50051
30+
DISPATCHER_HOST=http://0.0.0.0
31+
DISPATCHER_PORT=50052
32+
ETCD_URI=127.0.0.1:2379
33+
34+
MOQ_URI=http://localhost:4443/waterbus/
35+
HLS_MODE=LOCAL

0 commit comments

Comments
 (0)