fix :exam 修改缓存文件
This commit is contained in:
parent
1d913c99f4
commit
aa37c99ac4
|
@ -27,7 +27,7 @@ from apps.exam.parse_word import interpret_text
|
|||
import os
|
||||
import shutil
|
||||
from django.db.models import Q
|
||||
from django_redis import get_redis_connection
|
||||
from django.core.cache import cache
|
||||
import uuid
|
||||
# Create your views here.
|
||||
|
||||
|
@ -689,8 +689,7 @@ class ExamRecordViewSet(ListModelMixin, DestroyModelMixin, RetrieveModelMixin, G
|
|||
current_date = now_data.strftime('%Y-%m-%d')
|
||||
cer_number = now_data.strftime('%Y%m%d')
|
||||
# redis 连接并获取锁
|
||||
redis_conn = get_redis_connection("redis")
|
||||
identifier = acquire_lock(redis_conn, 'certificate', 10)
|
||||
cache.set("certificate", str(uuid.uuid4()), timeout=60)
|
||||
# 查询证明编号创建时间为最后一个
|
||||
cer = Certificate.objects.latest('证书编号')
|
||||
if cer:
|
||||
|
@ -712,12 +711,10 @@ class ExamRecordViewSet(ListModelMixin, DestroyModelMixin, RetrieveModelMixin, G
|
|||
serializer = CertificateSerializer(data=data_dict)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save()
|
||||
val = cache.get("certificate")
|
||||
if val: # 如果存在,则删除
|
||||
# 释放锁
|
||||
if identifier:
|
||||
release_lock(redis_conn, 'certificate', identifier)
|
||||
else:
|
||||
print("没有找到锁")
|
||||
|
||||
cache.delete("certificate")
|
||||
er.took = (now - er.create_time).total_seconds()
|
||||
er.end_time = now
|
||||
er.belong_dept=request.user.dept
|
||||
|
|
|
@ -196,14 +196,14 @@ AUTHENTICATION_BACKENDS = (
|
|||
|
||||
# 缓存配置
|
||||
CACHES = {
|
||||
"redis": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
"LOCATION": "redis://127.0.0.1:6379/1",
|
||||
"OPTIONS": {
|
||||
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
# "PICKLE_VERSION": -1
|
||||
}
|
||||
},
|
||||
# "redis": {
|
||||
# "BACKEND": "django_redis.cache.RedisCache",
|
||||
# "LOCATION": "redis://127.0.0.1:6379/1",
|
||||
# "OPTIONS": {
|
||||
# "CLIENT_CLASS": "django_redis.client.DefaultClient",
|
||||
# # "PICKLE_VERSION": -1
|
||||
# }
|
||||
# },
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
|
||||
'LOCATION': os.path.join(BASE_DIR, 'temp'),
|
||||
|
|
Loading…
Reference in New Issue