【发布时间】:2018-06-23 10:20:36
【问题描述】:
我使用两台 Parse 服务器,一台用于主数据库,一台用于 liveQuery。我还通过 AWS ElastiCache 设置了一个 redis。问题是当我在客户端(iOS)中使用实时查询时,没有显示任何事件。代码根本不响应任何更改。这里可能是什么问题?
一个问题:来自 AWS Elasticache 的 redisURL 是这样的:(这会在服务器启动时出错) appname.jajj2i.0001.use1.cache.amazonaws.com:6379
我应该像这样将 redis:// 添加到开头吗:(这就是我已经做过的) redis://appname.jajj2i.0001.use1.cache.amazonaws.com:6379
我的主要解析服务器代码如下:
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();
// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var S3Adapter = require('parse-server').S3Adapter
var api = new ParseServer({
databaseURI: "main_database_uri",
appId: "main_app_id",
masterKey: "main_master_key",
fileKey: "main_file_key",
serverURL: "main_server_rul",
liveQuery: {
classNames: ['Chats', 'Messages'],
redisURL: 'redis_url'
},
filesAdapter: new S3Adapter(
"S3_Key",
"S3_key",
"S3_bucket_name",
{directAccess: true}
),
});
// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);
var port = 1337;
app.listen(port, function() {
console.log('parse-server running on port ' + port);
});
//Parse Dashboard
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({
apps: [
{
appName: "My Bitnami Parse API",
appId: "appId",
masterKey: "masterKey",
fileKey: "fileKey",
production: true,
serverURL: "serverUrl"
}
],
users: [
{
user: "username",
pass: "password"
}
], useEncryptedPasswords: true
});
var allowInsecureHTTP = true;
// Serve the Parse Dashboard on the /parsedashboard URL prefix
app.use('/', dashboard);
var portdash = 4040;
app.listen(portdash, function() {
console.log('parse-dashboard running on port ' + portdash);
});
我的liveQuery服务器代码如下:
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var app = express();
// Specify the connection string for your mongodb database
// and the location to your Parse cloud code
var api = new ParseServer({
databaseURI: "main_database_uri",
appId: "live_appId",
masterKey: "live_master_key",
fileKey: "live_file_key",
serverURL: "live_server_url"
});
// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);
var port = 1337;
app.listen(port, function() {
console.log('parse-server running on port ' + port);
});
//Parse Dashboard
var ParseDashboard = require('parse-dashboard');
var dashboard = new ParseDashboard({
apps: [
{
appName: "My Bitnami Parse API",
appId: "appid",
masterKey: "masterkey",
fileKey: "filekey",
production: true,
serverURL: "serverUrl"
}
],
users: [
{
user: "username",
pass: "password"
}
], useEncryptedPasswords: true
});
var allowInsecureHTTP = true;
// Serve the Parse Dashboard on the /parsedashboard URL prefix
app.use('/', dashboard);
var portdash = 4040;
app.listen(portdash, function() {
console.log('parse-dashboard running on port ' + portdash);
});
var porthttp = 8030;
var httpServer = require('http').createServer(app);
httpServer.listen(porthttp, function() {
/* Create HTTP server successfully */
});
ParseServer.createLiveQueryServer(httpServer, {
redisURL: 'RedisUrl' // Redis URL from Main app
});
我的客户代码:
override func viewDidLoad() {
super.viewDidLoad()
let client = Client(server: "liveQuery_server", applicationId: "liveQuery_appId", clientKey: nil)
Chats.registerSubclass()
let query = PFQuery(className: "Chats").whereKey("chats", equalTo: "zaa")
subscription = client.subscribe(query)
subscription?.handle(Event.created) { (query, object) in
print(object)
}
}
【问题讨论】:
-
嘿 Atakan,我知道这已经过时了,但我也在努力使用 redis 设置实时查询服务器。你有没有想过这个问题?
-
很遗憾,我完全放弃了使用 liveQuery。
-
你最终改用了什么
-
Firebase 非常适合实时数据库。我切换到了@ZackShapiro
-
知道了。幸运的是,我能够弄清楚所有解析实时查询的内容
标签: swift amazon-web-services parse-platform redis