- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已经查看了 this answer并且无法弄清楚如何将其应用于我的问题,因此如果有答案,将不胜感激。
我也是 docker 和 docker-compose 的菜鸟。
我有一个简单的 docker-compose.yml
version: '3'
services:
redis:
image: "redis:alpine"
web:
build: . # current directory
command: bash -c "python /app/src/manage.py migrate &&
python /app/src/manage.py runserver 0.0.0.0:8000"
volumes:
- .:/app
ports:
- "8000:8000"
当我运行它时:docker-compose up
一切正常:
$ docker-compose up
Starting hackerspace_redis_1 ...
Starting hackerspace_redis_1 ... done
Starting hackerspace_web_1 ...
Starting hackerspace_web_1 ... done
Attaching to hackerspace_redis_1, hackerspace_web_1
redis_1 | 1:C 19 Jul 2019 16:49:10.644 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 19 Jul 2019 16:49:10.644 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 19 Jul 2019 16:49:10.644 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 19 Jul 2019 16:49:10.645 * Running mode=standalone, port=6379.
redis_1 | 1:M 19 Jul 2019 16:49:10.645 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 19 Jul 2019 16:49:10.645 # Server initialized
redis_1 | 1:M 19 Jul 2019 16:49:10.645 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1 | 1:M 19 Jul 2019 16:49:10.645 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1 | 1:M 19 Jul 2019 16:49:10.645 * DB loaded from disk: 0.000 seconds
redis_1 | 1:M 19 Jul 2019 16:49:10.645 * Ready to accept connections
web_1 | Operations to perform:
web_1 | Apply all migrations: account, admin, announcements, auth, badges, comments, contenttypes, courses, django_summernote, djconfig, djcytoscape, flatpages, notifications, portfolios, prerequisites, profile_manager, quest_manager, sessions, sites, socialaccount, suggestions, utilities
web_1 | Running migrations:
web_1 | No migrations to apply.
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | July 19, 2019 - 09:49:16
web_1 | Django version 2.0.13, using settings 'hackerspace_online.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
我可以通过浏览器在 127.0.0.0:8000 访问我的 django 应用程序。但是,当我尝试登录应用程序时,我得到:
ConnectionError at /accounts/login/
Error 111 connecting to 127.0.0.1:6379. Connection refused.
这是我在 Django 设置中连接到 Redis 的方式:
REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1')
REDIS_PORT = os.environ.get('REDIS_PORT', '6379')
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://{}:{}/1".format(REDIS_HOST, REDIS_PORT),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
#...
}
如何让我的 Django 应用程序连接到 Redis 容器?
请注意,据我所知,没有其他使用端口 6379(通过 sudo lsof -i -P -n | grep LISTEN
)
最佳答案
127.0.0.1
在 Docker 中几乎总是表示“这个容器”。如果您在 Docker Compose 下运行您的应用程序, 它
... sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
也就是说,在这个 docker-compose.yml
文件的上下文中,有主机名 redis
和 web
指向两个容器。
您已经完成了一项重要的配置工作。当你的代码说
REDIS_HOST = os.environ.get('REDIS_HOST', '127.0.0.1')
您可以设置一个覆盖内置默认值的环境变量。所以在这里你只需要在你的 docker-compose.yml
文件中添加一个环境变量设置:
version: '3'
services:
redis:
image: "redis:alpine"
web:
build: . # current directory
environment:
- REDIS_HOST=redis
ports:
- "8000:8000"
# application source code and default command are built into the image
关于django - docker-compose + django + redis - 错误 111 连接到 127.0.0.1 :6379. 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57116745/
我有一个关于 Redis Pubsub 的练习,如下所示: 如果发布者发布消息但订阅者没有收到服务器崩溃。订阅者如何在重启服务器时收到该消息? 请帮帮我,谢谢! 最佳答案 在这种情况下,消息将永远消失
我们正在使用 Service Stack 的 RedisClient 的 BlockingDequeue 来保存一些数据,直到它可以被处理。调用代码看起来像 using (var client =
我有一个 Redis 服务器和多个 Redis 客户端。每个 Redis 客户端都是一个 WebSocket+HTTP 服务器,其中包括管理 WebSocket 连接。这些 WebSocket+HTT
我有多个 Redis 实例。我使用不同的端口创建了一个集群。现在我想将数据从预先存在的 redis 实例传输到集群。我知道如何将数据从一个实例传输到集群,但是当实例多于一个时,我无法做到这一点。 最佳
配置:三个redis集群分区,跨三组一主一从。当 Master 宕机时,Lettuce 会立即检测到中断并开始重试。但是,Lettuce 没有检测到关联的 slave 已经将自己提升为 master
我想根据从指定集合中检索这些键来删除 Redis 键(及其数据集),例如: HMSET id:1 password 123 category milk HMSET id:2 password 456
我正在编写一个机器人(其中包含要禁用的命令列表),用于监视 Redis。它通过执行禁用命令,例如 (rename-command ZADD "")当我重新启动我的机器人时,如果要禁用的命令列表发生变化
我的任务是为大量听众使用发布/订阅。这是来自 docs 的订阅的简化示例: r = redis.StrictRedis(...) p = r.pubsub() p.subscribe('my-firs
我一直在阅读有关使用 Redis 哨兵进行故障转移的内容。我打算有1个master+1个slave,如果master宕机超过1分钟,就把slave变成master。我知道这在 Sentinel 中是
与仅使用常规 Redis 和创建分片相比,使用 Redis 集群有哪些优势? 在我看来,Redis Cluster 更注重数据安全(让主从架构解决故障)。 最佳答案 我认为当您需要在不丢失任何数据的情
由于 Redis 以被动和主动方式使 key 过期, 有没有办法得到一个 key ,即使它的过期时间已过 (但 在 Redis 中仍然存在 )? 最佳答案 DEBUG OBJECT myKey 将返回
我想用redis lua来实现monitor命令,而不是redis-cli monitor。但我不知道怎么办。 redis.call('monitor') 不起作用。 最佳答案 您不能从 Redis
我读过 https://github.com/redisson/redisson 我发现有几个 Redis 复制设置(包括对 AWS ElastiCache 和 Azure Redis 缓存的支持)
Microsoft.AspNet.SignalR.Redis 和 StackExchange.Redis.Extensions.Core 在同一个项目中使用。前者需要StackExchange.Red
1. 认识 Redis Redis(Remote Dictionary Server)远程词典服务器,是一个基于内存的键值对型 NoSQL 数据库。 特征: 键值(key-value)型,value
1. Redis 数据结构介绍 Redis 是一个 key-value 的数据库,key 一般是 String 类型,但 value 类型多种多样,下面就举了几个例子: value 类型 示例 Str
1. 什么是缓存 缓存(Cache) 就是数据交换的缓冲区,是存贮数据的临时地方,一般读写性能较高。 缓存的作用: 降低后端负载 提高读写效率,降低响应时间 缓存的成本: 数据一致性成本 代码维护成本
我有一份记录 list 。对于我的每条记录,我都需要进行一些繁重的计算,因为我要在Redis中创建反向索引。为了达到到达记录,需要在管道中执行多个redis命令(sadd为100 s + set为1
我有一个三节点Redis和3节点哨兵,一切正常,所有主服务器和从属服务器都经过验证,并且哨兵配置文件已与所有Redis和哨兵节点一起更新,但是问题是当Redis主服务器关闭并且哨兵希望选举失败者时再次
我正在尝试计算Redis中存储的消息之间的响应时间。但是我不知道该怎么做。 首先,我必须像这样存储chat_messages的时间流 ZADD conversation:CONVERSATION_ID
我是一名优秀的程序员,十分优秀!