Skip to content

Commit

Permalink
Add default port to stress redis storage (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
texuf authored Aug 12, 2024
1 parent 9daf077 commit 4bdacfa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/stress/scripts/gamma_chat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export CONTAINER_COUNT="${CONTAINER_COUNT:1}"
export STRESS_DURATION="${STRESS_DURATION:-180}"
export PROCESSES_PER_CONTAINER="${PROCESSES_PER_CONTAINER:-3}"
export CLIENTS_COUNT="${CLIENTS_COUNT:-12}"
export RANDOM_CLIENTS_COUNT="${RANDOM_CLIENTS_COUNT:-5}"

export RIVER_ENV="${RIVER_ENV:-gamma}"
export STRESS_MODE="${STRESS_MODE:-chat}"
Expand Down
1 change: 1 addition & 0 deletions packages/stress/scripts/localhost_chat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export SESSION_ID="${SESSION_ID:-$(uuidgen)}"

export PROCESSES_PER_CONTAINER="${PROCESSES_PER_CONTAINER:-4}"
export CLIENTS_COUNT="${CLIENTS_COUNT:-100}"
export RANDOM_CLIENTS_COUNT="${RANDOM_CLIENTS_COUNT:-5}"

export MNEMONIC="toy alien remain valid print employ age multiply claim student story aware"
export WALLET_ADDRESS="0x95D7701A0Faa5F514B4c5B49bf66580fCE9ffbf7"
Expand Down
19 changes: 15 additions & 4 deletions packages/stress/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@ export interface IStorage {
close(): Promise<void>
}

function parseRedisUrl(uri: string) {
const defaultRedisPort = 6379
try {
const url = new URL(uri)
const host = `${url.protocol}//${url.hostname}`
const port = url.port.length > 0 ? parseInt(url.port) : defaultRedisPort
const opts = host.includes('localhost') ? { port } : { host, port }
return opts
} catch (error) {
return { host: uri, port: defaultRedisPort }
}
}

export class RedisStorage implements IStorage {
private client: Redis

constructor(uri: string) {
const url = new URL(uri)
const host = `${url.protocol}//${url.hostname}`
const port = parseInt(url.port)
const opts = host.includes('localhost') ? { port } : { host, port }
const opts = parseRedisUrl(uri)
logger.log('New Redis connection', opts)
this.client = new Redis(opts)
}
async get(key: string): Promise<string | null> {
Expand Down

0 comments on commit 4bdacfa

Please sign in to comment.