Skip to content

Commit 36aae13

Browse files
committed
Add Redis + upgrade packages
1 parent b9c3e39 commit 36aae13

File tree

15 files changed

+294
-249
lines changed

15 files changed

+294
-249
lines changed

.env.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CORS_ALLOW_ORIGIN=*
1818

1919
# Doctrine
2020
DATABASE_URL="mysql://:@:3306/"
21+
REDIS_URL="redis://redis:6379"
2122

2223
# Docker
2324
MYSQL_ROOT_PASSWORD=

LOCAL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ docker exec -it api-sf php bin/console doctrine:migrations:migrate
1414

1515

1616
# Try Redis cache load
17-
wrk -t4 -c200 -d30s http://localhost:9080/api/tokens
17+
wrk -t4 -c50 -d30s http://localhost:9080/api/tokens
1818

1919
# Upgrade Symfony version
2020
docker exec -it api-sf php bin/console debug:container --deprecations

config/packages/cache.yaml

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
11
framework:
22
cache:
33
# Unique name of your app: used to compute stable namespaces for cache keys.
4-
#prefix_seed: your_vendor_name/app_name
4+
prefix_seed: realtoken_community/api_php
55

66
# The "app" cache stores to the filesystem by default.
7-
# The data in this cache should persist between deploys.
8-
# Other options include:
9-
107
# Redis
11-
#app: cache.adapter.redis
12-
#default_redis_provider: redis://localhost
13-
14-
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
15-
#app: cache.adapter.apcu
8+
app: cache.adapter.redis
9+
default_redis_provider: '%env(REDIS_URL)%'
1610

1711
# Namespaced pools use the above "app" backend by default
18-
#pools:
19-
#my.dedicated.cache: null
12+
pools:
13+
nelmio_api_doc_pool:
14+
adapter: cache.app
15+
default_lifetime: "7 days"
16+
# fallbacks: 'cache.adapter.file_system'
17+
tokens_cache:
18+
adapter: cache.app
19+
default_lifetime: 86400 # 24 hours in seconds
20+
# TODO : Mettre le cache sur les sessions
21+
# session:
22+
# handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler
23+
# cookie_secure: auto
24+
# cookie_samesite: lax
25+
# cookie_lifetime: 86400
26+
# storage_factory_id: session.storage.factory.native
27+
# save_path: "%env(REDIS_URL)%"
28+
29+
# config/packages/cache.yaml
30+
#services:
31+
# app.cache.adapter.redis:
32+
# parent: "cache.adapter.redis"
33+
# arguments:
34+
# $redis: "@Redis"
35+
# $defaultLifetime: 604800 # 7 days in seconds
36+
## - '@Redis'
37+
## - '%env(APP_CACHE_NAMESPACE)%' # optional namespace prefix for keys, e.g. "app_cache"
38+
## - '%env(int:APP_CACHE_DEFAULT_LIFETIME)%' # optional default lifetime in seconds, e.g. 3600 (1 hour)
39+
## pools:
40+
## app.tokens_cache:
41+
## adapter: cache.adapter.redis
42+
## provider: 'redis://redis'
43+
## cache.rate_limiter:
44+
## adapter: cache.adapter.redis
45+
## provider: '%env(REDIS_URL)%'

config/packages/doctrine.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ doctrine:
66
# types:
77
# array: Doctrine\DBAL\Types\ArrayType
88
orm:
9-
auto_generate_proxy_classes: true
9+
# auto_generate_proxy_classes: true
1010
enable_lazy_ghost_objects: true
11-
enable_native_lazy_objects: false # garde l’ancien comportement
12-
# enable_native_lazy_objects: true # active les lazy objects natifs, si tu veux tester et t’adapter avant DoctrineBundle 3.
11+
# enable_native_lazy_objects: false # garde l’ancien comportement
12+
enable_native_lazy_objects: true # active les lazy objects natifs, si tu veux tester et t’adapter avant DoctrineBundle 3.
1313
report_fields_where_declared: true
1414
validate_xml_mapping: true
1515
# naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
nelmio_api_doc:
2-
documentation:
3-
info:
4-
title: RealToken Community API Doc
5-
description: The unique RealToken API from Community
6-
version: 1.5.0
7-
components:
8-
securitySchemes:
9-
api_key:
10-
type: apiKey
11-
name: 'X-AUTH-REALT-TOKEN'
12-
in: header
13-
# Bearer:
14-
# type: http
15-
# scheme: bearer
16-
# bearerFormat: JWT
17-
security:
18-
- api_key: []
19-
# - bearerAuth: []
20-
areas:
21-
path_patterns:
22-
- ^/v1
23-
# - ^/v1(?!/doc$)
24-
html_config:
25-
redocly_config:
26-
disableTryIt: false
27-
disableTryItRequestUrlEncoding: false
28-
expandDefaultServerVariables: true
29-
expandResponses: '200,201'
30-
expandSingleSchemaField: true
31-
hideHostname: false
32-
hideRequestPayloadSample: false
33-
menuToggle: true
34-
showObjectSchemaExamples: true
2+
documentation:
3+
info:
4+
title: RealToken Community API Doc
5+
description: The unique RealToken API from Community
6+
version: 1.5.0
7+
components:
8+
securitySchemes:
9+
api_key:
10+
type: apiKey
11+
name: 'X-AUTH-REALT-TOKEN'
12+
in: header
13+
# Bearer:
14+
# type: http
15+
# scheme: bearer
16+
# bearerFormat: JWT
17+
security:
18+
- api_key: []
19+
# - bearerAuth: []
20+
cache:
21+
pool: 'nelmio_api_doc_pool'
22+
item_id: 'nelmio_api_doc_cache'
23+
24+
areas:
25+
path_patterns:
26+
- ^/v1
27+
# - ^/v1(?!/doc$)
28+
html_config:
29+
redocly_config:
30+
disableTryIt: false
31+
disableTryItRequestUrlEncoding: false
32+
expandDefaultServerVariables: true
33+
expandResponses: '200,201'
34+
expandSingleSchemaField: true
35+
hideHostname: false
36+
hideRequestPayloadSample: false
37+
menuToggle: true
38+
showObjectSchemaExamples: true

config/packages/noxlogic_rate_limit.yaml

Lines changed: 0 additions & 40 deletions
This file was deleted.

config/packages/rate_limiter.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ framework:
2424
policy: 'sliding_window'
2525
limit: 1
2626
interval: '60 minutes'
27+
28+
# config/packages/rate_limiter.yaml
29+
api:
30+
policy: 'sliding_window'
31+
limit: 1 # ajuste selon role
32+
interval: '1 minute'
33+
# storage_service: 'redis.rate_limiter'
34+
# storage_service: 'cache.rate_limiter'
35+
# storage_service: 'rate_limiter.storage.redis'
36+
#services:
37+
# redis.rate_limiter:
38+
# class: Symfony\Component\RateLimiter\Storage\RedisStorage
39+
# arguments:
40+
# - '@snc_redis.default' # ou \Redis via DSN redis://...

config/routes/framework.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
when@dev:
2-
_errors:
3-
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
4-
prefix: /_error
2+
_errors:
3+
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
4+
prefix: /_error

config/routes/security.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
_security_logout:
2-
resource: security.route_loader.logout
3-
type: service
2+
resource: security.route_loader.logout
3+
type: service

config/services.yaml

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,42 @@
66
parameters:
77

88
services:
9-
# default configuration for services in *this* file
10-
_defaults:
11-
autowire: true # Automatically injects dependencies in your services.
12-
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
13-
14-
# makes classes in src/ available to be used as services
15-
# this creates a service per class whose id is the fully-qualified class name
16-
App\:
17-
resource: '../src/'
18-
exclude:
19-
- '../src/DependencyInjection/'
20-
- '../src/Entity/'
21-
- '../src/Kernel.php'
22-
# App\Controller\TokenController:
23-
# tags: ['controller.service_arguments']
24-
App\Controller\:
25-
resource: '../src/Controller'
26-
tags: [ 'controller.service_arguments' ]
27-
28-
App\EventSubscriber\RateLimitSubscriber:
29-
arguments:
30-
$limiters: !tagged_iterator
31-
tag: 'rate_limiter'
32-
index_by: 'name'
33-
tags:
34-
- { name: kernel.event_subscriber }
35-
36-
App\Service\QuotaService:
37-
arguments:
38-
$limiters: !tagged_iterator
39-
tag: 'rate_limiter'
40-
index_by: 'name'
41-
42-
App\Service\RequestContextService: ~
43-
44-
Web3p\EthereumUtil\Util: ~
9+
_defaults:
10+
autowire: true
11+
autoconfigure: true
12+
13+
App\:
14+
resource: '../src/'
15+
exclude:
16+
- '../src/DependencyInjection/'
17+
- '../src/Entity/'
18+
- '../src/Kernel.php'
19+
20+
App\Controller\:
21+
resource: '../src/Controller'
22+
tags: [ 'controller.service_arguments' ]
23+
24+
App\EventSubscriber\RateLimitSubscriber:
25+
arguments:
26+
$limiters: !tagged_iterator { tag: 'rate_limiter', index_by: 'name' }
27+
tags:
28+
- { name: kernel.event_subscriber }
29+
30+
App\Service\QuotaService:
31+
arguments:
32+
$limiters: !tagged_iterator { tag: 'rate_limiter', index_by: 'name' }
33+
34+
App\Service\RequestContextService: ~
35+
36+
# Web3p\EthereumUtil\Util: ~
37+
38+
Redis:
39+
class: Redis
40+
factory: [ 'Redis', 'connect' ]
41+
arguments:
42+
- '%env(REDIS_URL)%'
43+
44+
rate_limiter.storage.redis:
45+
class: Symfony\Component\RateLimiter\Storage\RedisStorage
46+
arguments:
47+
- '@Redis'

0 commit comments

Comments
 (0)