我正在尝试在 docker 上设置一主一从和一哨兵,为此我编写了这个 docker compose 文件。
version: '3'
services:
redis-master:
container_name: "redis-master"
image: redis
ports:
- "6379:6379"
command: "redis-server /etc/redis.conf"
volumes:
- "./data/master:/data/"
- "./master.conf:/etc/redis.conf"
redis-slave:
container_name: "redis-slave"
image: redis
ports:
- "6380:6379"
command: "redis-server /etc/redis.conf"
volumes:
- "./data/slave:/data/"
- "./slave.conf:/etc/redis.conf"
depends_on:
- redis-master
redis-sentinel:
container_name: 'redis-sentinel'
image: redis
ports:
- "26379:26379"
command: >
bash -c "chmod 777 /etc/sentinel.conf
&& redis-server /etc/sentinel.conf --sentinel"
volumes:
- "./sentinel.conf:/etc/sentinel.conf"
depends_on:
- redis-master
- redis-slave
Run Code Online (Sandbox Code Playgroud)
sudo docker-compose up --build --force
但是,当我尝试使用除 redis-sentinel 之外的所有服务构建它时,所有服务都运行良好。我在日志中收到此错误
redis-sentinel …
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行 celery -A 项目工作人员 -l 信息。但每次它都会返回一个错误,例如init遇到意外错误。请帮助。提前致谢。
我的设置文件:
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Africa/Nairobi'
Run Code Online (Sandbox Code Playgroud)
芹菜文件:
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# setting the Django settings module.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
app = Celery('project')
app.config_from_object('django.conf:settings', namespace='CELERY')
# Looks up for task modules in Django applications and loads them
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task():
print('Request')
Run Code Online (Sandbox Code Playgroud)
初始化文件
from __future__ import absolute_import
# This will make sure …
Run Code Online (Sandbox Code Playgroud) 假设我有一个 JavaScript 对象,其结构如下:
{
id: "someUniqueId",
foo: "otherData",
bar: 30
}
Run Code Online (Sandbox Code Playgroud)
我想在RedisJSON中存储数百个。我目前正在使用node-redis 客户端将密钥初始化'json-objects'
为空对象:
await client.json.set('json-objects', `$`, {});
Run Code Online (Sandbox Code Playgroud)
然后,我将对象添加到该键的根对象,例如:
const dataToStore = {
id: "someUniqueId",
foo: "otherData",
bar: 30
}
await client.json.set('json-objects', `$.${dataToStore.id}`, dataToStore as any);
Run Code Online (Sandbox Code Playgroud)
这会导致键下出现一个大对象,'json-objects'
如下所示:
{
"someUniqueId-1": {
id: "someUniqueId-1",
foo: "otherData",
bar: 30
},
"someUniqueId-2": {
id: "someUniqueId-2",
foo: "otherData2",
bar: 31
},
"someUniqueId-3": {
id: "someUniqueId-3",
foo: "otherData3",
bar: 32
},
and so on...
}
Run Code Online (Sandbox Code Playgroud)
然后我可以使用路径查询和更新:
await client.json.set('json-objects', `$.${id}.foo`, "someUpdatedData"); …
Run Code Online (Sandbox Code Playgroud) psc := redis.PubSubConn{c}
psc.Subscribe("example")
func Receive() {
for {
switch v := psc.Receive().(type) {
case redis.Message:
fmt.Printf("%s: message: %s\n", v.Channel, v.Data)
case redis.Subscription:
fmt.Printf("%s: %s %d\n", v.Channel, v.Kind, v.Count)
case error:
return v
}
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中(取自Redigo doc),如果连接丢失,所有订阅也会丢失.什么是从丢失的连接恢复和重新订阅更好的方法.
连接 redis-cli 时出现此错误。请帮我解决这个问题。
tony@kali:~$ redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
Run Code Online (Sandbox Code Playgroud)