我正在尝试为我的应用程序设置memcached。 在本地就可以了。
现在是时候部署到真实服务器上了,我正在使用Google Cloud App Engine Flex环境。
这是一个自定义运行时。 我可以很好地安装我的应用程序,但是在运行时,对于使用Memcached的视图,我得到了500。
我的第一个想法是由于缓存设置:
[Fact]
public async Task CreateApplication_WhenCalled_ShouldStoreApplication()
{
// I have already mocked unitofwork in constructor
// when InsertAsync method will called, it will assign passed argument to declared private field (application)
Application application;
UnitOfWork.Setup(x => x.Application.InsertAsync(It.IsAny<Application>()))
.Callback<Application>(app => application = app);
//act
await _applicationService.CreateApplication(new CreateApplicationdRequest()); // dummy request
//assert
UnitOfWork.Verify(x => x.Application.InsertAsync(It.IsAny<Application>()), Times.Once);
UnitOfWork.Verify(x => x.CommitAsync(), Times.Once);
//here I am checking generated application's state
Assert.Equal(application.CustomerId, request.CustomerId);
Assert.Equal(application.Applicant.PhoneNumber, request.PhoneNumber);
Assert.Equal(application.LoanCurrencyId, request.LoanCurrencyId);
Assert.Equal(application.TermType, request.TermType);
Assert.Equal(application.Term, request.Term);
Assert.Equal("01017054322_CC-01001", application.DocumentNo);
Assert.Equal(application.GracePeriod, request.DefaultGracePeriod);
}
我认为这与该位置设置有关。 既然此“ 127.0.0.1:11211”适用于本地环境,如何为gcloud自定义运行时Flex环境设置位置?
如果那不是我得到500的原因,那可能是更好的设置。 这是我的docker文件:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
'LOCATION': '127.0.0.1:11211',
}
和app.yaml文件:
FROM python:3.8
EXPOSE 8080
RUN apt-get update && apt-get install --reinstall -y \
binutils \
libproj-dev \
libmemcached11 \
libmemcachedutil2 \
libmemcached-dev \
libz-dev
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
ADD . .
# Run a WSGI server to serve the application. gunicorn must be declared as
CMD exec gunicorn --bind :8080 --workers 1 --threads 8 main:app --timeout 0 --preload
答案 0 :(得分:0)
根据App Engine Flexible Official Documentation,Memcache服务在App Engine灵活环境中不可用。要缓存应用程序数据,可以使用Memorystore for Redis。您可以阅读下一份文档,以连接到您的Redis instance from an App Engine flexible environment application
还请记住,根据App Engine Flexible环境Python 3.8 is still not supported的官方文档。 但是现在App Engine Standard does support Python 3.8。