A .redis used in django
1. a manner (not recommended by the connection pool)
redis_pool.py
import redis Pool= redis.ConnectionPool(host='localhost', port=6379)
urls.py
from django.contrib import admin from django.urls import path from myapp import views urlpatterns = [ path('admin/', admin.site.urls), path('index/', views.index), path('home/', views.home), ]
views.py
from django.shortcuts import render,HttpResponse import redis from uits.redis_pool import # Pool 引入连接池 def index(request): conn = redis.Redis(connection_pool=Pool) conn.hset ( " K1 " , " Age " , 18 is ) return the HttpResponse ( " This is the setting value " ) def home(request): conn = redis.Redis(connection_pool=Pool) aa=conn.hget("k1","age") print(aa) return HttpResponse("获取值")