Skip to content

Commit 0dca1fa

Browse files
refactor: Separate Redis host and port configuration
This commit refactors the Redis connection settings to use distinct `REDIS_HOST` and `REDIS_PORT` environment variables instead of a single `REDIS_URL`. This change improves configuration clarity and flexibility across environments. Additionally, it removes an incorrect custom `save` method from the `User` model. The previous implementation improperly set the `last_login` field upon user creation. This logic is flawed, as the `last_login` field should be managed by Django's authentication backend during the actual login process.
1 parent 2b936fa commit 0dca1fa

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ POSTGRES_PASSWORD=your_postgres_password
1212
POSTGRES_PORT=5432
1313
POSTGRES_USERNAME=your_postgres_username
1414

15-
REDIS_URL=redis://redis:6379/0
15+
REDIS_HOST=redis
16+
REDIS_PORT=6379

promo_code/promo_code/settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,13 @@ def load_bool(name, default):
142142
'PORT': os.getenv('POSTGRES_PORT', '5432'),
143143
},
144144
}
145+
REDIS_HOST = os.getenv('REDIS_HOST', 'redis')
146+
REDIS_PORT = os.getenv('REDIS_PORT', '6379')
145147

146148
CACHES = {
147149
'default': {
148150
'BACKEND': 'django_redis.cache.RedisCache',
149-
'LOCATION': os.getenv('REDIS_URL', 'redis://127.0.0.1:6379/0'),
151+
'LOCATION': f'redis://{REDIS_HOST}:{REDIS_PORT}/0',
150152
'OPTIONS': {
151153
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
152154
},

promo_code/user/models.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ class User(
7878
def __str__(self):
7979
return self.email
8080

81-
def save(self, *args, **kwargs):
82-
if not self.pk:
83-
self.last_login = django.utils.timezone.now()
84-
85-
super().save(*args, **kwargs)
86-
8781

8882
class PromoLike(django.db.models.Model):
8983
id = django.db.models.UUIDField(

0 commit comments

Comments
 (0)