Skip to content

Commit

Permalink
テストなどにKeyDBを使うように (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
u1-liquid authored Oct 29, 2023
1 parent 42bc281 commit db7a17d
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .config/docker_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ dbReplications: false
#───┘ Redis configuration └─────────────────────────────────────

redis:
host: redis
host: keydb
port: 6379
#family: 0 # 0=Both, 4=IPv4, 6=IPv6
#pass: example-pass
#prefix: example-prefix
#db: 1

#redisForPubsub:
# host: redis
# host: keydb
# port: 6379
# #family: 0 # 0=Both, 4=IPv4, 6=IPv6
# #pass: example-pass
# #prefix: example-prefix
# #db: 1

#redisForJobQueue:
# host: redis
# host: keydb
# port: 6379
# #family: 0 # 0=Both, 4=IPv4, 6=IPv6
# #pass: example-pass
Expand Down
6 changes: 3 additions & 3 deletions .devcontainer/devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ dbReplications: false
#───┘ Redis configuration └─────────────────────────────────────

redis:
host: redis
host: keydb
port: 6379
#family: 0 # 0=Both, 4=IPv4, 6=IPv6
#pass: example-pass
#prefix: example-prefix
#db: 1

#redisForPubsub:
# host: redis
# host: keydb
# port: 6379
# #family: 0 # 0=Both, 4=IPv4, 6=IPv6
# #pass: example-pass
# #prefix: example-prefix
# #db: 1

#redisForJobQueue:
# host: redis
# host: keydb
# port: 6379
# #family: 0 # 0=Both, 4=IPv4, 6=IPv6
# #pass: example-pass
Expand Down
10 changes: 5 additions & 5 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ services:
- internal_network
- external_network

redis:
keydb:
restart: unless-stopped
image: redis:7-alpine
image: eqalpha/keydb:latest
networks:
- internal_network
volumes:
- redis-data:/data
- keydb-data:/data
healthcheck:
test: "redis-cli ping"
test: "keydb-cli ping"
interval: 5s
retries: 20

Expand All @@ -45,7 +45,7 @@ services:

volumes:
postgres-data:
redis-data:
keydb-data:

networks:
internal_network:
Expand Down
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ docker-compose.yml
node_modules/
packages/*/node_modules
redis/
keydb/
files/
misskey-assets/
fluent-emojis/
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:

services:
postgres:
image: postgres:13
image: postgres:15
ports:
- 54312:5432
env:
POSTGRES_DB: test-misskey
POSTGRES_HOST_AUTH_METHOD: trust
redis:
image: redis:7
keydb:
image: eqalpha/keydb:latest
ports:
- 56312:6379

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ jobs:

services:
postgres:
image: postgres:13
image: postgres:15
ports:
- 54312:5432
env:
POSTGRES_DB: test-misskey
POSTGRES_HOST_AUTH_METHOD: trust
redis:
image: redis:7
keydb:
image: eqalpha/keydb:latest
ports:
- 56312:6379

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ coverage
!/.config/docker_example.env
docker-compose.yml
!/.devcontainer/docker-compose.yml
!/packages/backend/test/docker-compose.yml

# misskey
/build
Expand All @@ -51,6 +52,7 @@ run.bat
api-docs.json
*.log
/redis
/keydb
*.code-workspace
.DS_Store
/files
Expand Down
6 changes: 3 additions & 3 deletions chart/templates/Deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
ports:
- containerPort: 3000
- name: postgres
image: postgres:14-alpine
image: postgres:15-alpine
env:
- name: POSTGRES_USER
value: "example-misskey-user"
Expand All @@ -37,8 +37,8 @@ spec:
value: "misskey"
ports:
- containerPort: 5432
- name: redis
image: redis:alpine
- name: keydb
image: eqalpha/keydb:latest
ports:
- containerPort: 6379
volumes:
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ services:
restart: always
links:
- db
- redis
- keydb
# - meilisearch
depends_on:
db:
condition: service_healthy
redis:
keydb:
condition: service_healthy
ports:
- "3000:3000"
Expand All @@ -22,15 +22,15 @@ services:
- ./files:/misskey/files
- ./.config:/misskey/.config:ro

redis:
keydb:
restart: always
image: redis:7-alpine
image: eqalpha/keydb:latest
networks:
- internal_network
volumes:
- ./redis:/data
- ./keydb:/data
healthcheck:
test: "redis-cli ping"
test: "keydb-cli ping"
interval: 5s
retries: 20

Expand Down
10 changes: 5 additions & 5 deletions packages/backend/src/core/FeaturedService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class FeaturedService {
redisTransaction.expire(
`${name}:${currentWindow}`,
(windowRange * 3) / 1000,
'NX'); // "NX -- Set expiry only when the key has no expiry" = 有効期限がないときだけ設定
);
await redisTransaction.exec();
}

Expand All @@ -48,10 +48,10 @@ export class FeaturedService {
const previousWindow = currentWindow - 1;

const redisPipeline = this.redisClient.pipeline();
redisPipeline.zrange(
`${name}:${currentWindow}`, 0, threshold, 'REV', 'WITHSCORES');
redisPipeline.zrange(
`${name}:${previousWindow}`, 0, threshold, 'REV', 'WITHSCORES');
redisPipeline.zrevrange(
`${name}:${currentWindow}`, 0, threshold, 'WITHSCORES');
redisPipeline.zrevrange(
`${name}:${previousWindow}`, 0, threshold, 'WITHSCORES');
const [currentRankingResult, previousRankingResult] = await redisPipeline.exec().then(result => result ? result.map(r => r[1] as string[]) : [[], []]);

const ranking = new Map<string, number>();
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
version: "3"

services:
redistest:
image: redis:7
keydbtest:
image: eqalpha/keydb:latest
ports:
- "127.0.0.1:56312:6379"

dbtest:
image: postgres:13
image: postgres:15
ports:
- "127.0.0.1:54312:5432"
environment:
Expand Down

0 comments on commit db7a17d

Please sign in to comment.