LiveQuery: Add options for Redis (#5584)
Closes: https://github.com/parse-community/parse-server/issues/5387
This commit is contained in:
@@ -28,6 +28,7 @@ describe('ParsePubSub', function() {
|
|||||||
it('can create redis publisher', function() {
|
it('can create redis publisher', function() {
|
||||||
ParsePubSub.createPublisher({
|
ParsePubSub.createPublisher({
|
||||||
redisURL: 'redisURL',
|
redisURL: 'redisURL',
|
||||||
|
redisOptions: { socket_keepalive: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub')
|
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub')
|
||||||
@@ -36,6 +37,7 @@ describe('ParsePubSub', function() {
|
|||||||
.EventEmitterPubSub;
|
.EventEmitterPubSub;
|
||||||
expect(RedisPubSub.createPublisher).toHaveBeenCalledWith({
|
expect(RedisPubSub.createPublisher).toHaveBeenCalledWith({
|
||||||
redisURL: 'redisURL',
|
redisURL: 'redisURL',
|
||||||
|
redisOptions: { socket_keepalive: true },
|
||||||
});
|
});
|
||||||
expect(EventEmitterPubSub.createPublisher).not.toHaveBeenCalled();
|
expect(EventEmitterPubSub.createPublisher).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -54,6 +56,7 @@ describe('ParsePubSub', function() {
|
|||||||
it('can create redis subscriber', function() {
|
it('can create redis subscriber', function() {
|
||||||
ParsePubSub.createSubscriber({
|
ParsePubSub.createSubscriber({
|
||||||
redisURL: 'redisURL',
|
redisURL: 'redisURL',
|
||||||
|
redisOptions: { socket_keepalive: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub')
|
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub')
|
||||||
@@ -62,6 +65,7 @@ describe('ParsePubSub', function() {
|
|||||||
.EventEmitterPubSub;
|
.EventEmitterPubSub;
|
||||||
expect(RedisPubSub.createSubscriber).toHaveBeenCalledWith({
|
expect(RedisPubSub.createSubscriber).toHaveBeenCalledWith({
|
||||||
redisURL: 'redisURL',
|
redisURL: 'redisURL',
|
||||||
|
redisOptions: { socket_keepalive: true },
|
||||||
});
|
});
|
||||||
expect(EventEmitterPubSub.createSubscriber).not.toHaveBeenCalled();
|
expect(EventEmitterPubSub.createSubscriber).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,19 +9,27 @@ describe('RedisPubSub', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can create publisher', function() {
|
it('can create publisher', function() {
|
||||||
RedisPubSub.createPublisher({ redisURL: 'redisAddress' });
|
RedisPubSub.createPublisher({
|
||||||
|
redisURL: 'redisAddress',
|
||||||
|
redisOptions: { socket_keepalive: true },
|
||||||
|
});
|
||||||
|
|
||||||
const redis = require('redis');
|
const redis = require('redis');
|
||||||
expect(redis.createClient).toHaveBeenCalledWith('redisAddress', {
|
expect(redis.createClient).toHaveBeenCalledWith('redisAddress', {
|
||||||
|
socket_keepalive: true,
|
||||||
no_ready_check: true,
|
no_ready_check: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can create subscriber', function() {
|
it('can create subscriber', function() {
|
||||||
RedisPubSub.createSubscriber({ redisURL: 'redisAddress' });
|
RedisPubSub.createSubscriber({
|
||||||
|
redisURL: 'redisAddress',
|
||||||
|
redisOptions: { socket_keepalive: true },
|
||||||
|
});
|
||||||
|
|
||||||
const redis = require('redis');
|
const redis = require('redis');
|
||||||
expect(redis.createClient).toHaveBeenCalledWith('redisAddress', {
|
expect(redis.createClient).toHaveBeenCalledWith('redisAddress', {
|
||||||
|
socket_keepalive: true,
|
||||||
no_ready_check: true,
|
no_ready_check: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import redis from 'redis';
|
import redis from 'redis';
|
||||||
|
|
||||||
function createPublisher({ redisURL }): any {
|
function createPublisher({ redisURL, redisOptions = {} }): any {
|
||||||
return redis.createClient(redisURL, { no_ready_check: true });
|
redisOptions.no_ready_check = true;
|
||||||
|
return redis.createClient(redisURL, redisOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSubscriber({ redisURL }): any {
|
function createSubscriber({ redisURL, redisOptions = {} }): any {
|
||||||
return redis.createClient(redisURL, { no_ready_check: true });
|
redisOptions.no_ready_check = true;
|
||||||
|
return redis.createClient(redisURL, redisOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
const RedisPubSub = {
|
const RedisPubSub = {
|
||||||
|
|||||||
@@ -377,6 +377,11 @@ module.exports.LiveQueryOptions = {
|
|||||||
help: 'LiveQuery pubsub adapter',
|
help: 'LiveQuery pubsub adapter',
|
||||||
action: parsers.moduleOrObjectParser,
|
action: parsers.moduleOrObjectParser,
|
||||||
},
|
},
|
||||||
|
redisOptions: {
|
||||||
|
env: 'PARSE_SERVER_LIVEQUERY_REDIS_OPTIONS',
|
||||||
|
help: "parse-server's LiveQuery redisOptions",
|
||||||
|
action: parsers.objectParser,
|
||||||
|
},
|
||||||
redisURL: {
|
redisURL: {
|
||||||
env: 'PARSE_SERVER_LIVEQUERY_REDIS_URL',
|
env: 'PARSE_SERVER_LIVEQUERY_REDIS_URL',
|
||||||
help: "parse-server's LiveQuery redisURL",
|
help: "parse-server's LiveQuery redisURL",
|
||||||
@@ -421,6 +426,11 @@ module.exports.LiveQueryServerOptions = {
|
|||||||
help: 'LiveQuery pubsub adapter',
|
help: 'LiveQuery pubsub adapter',
|
||||||
action: parsers.moduleOrObjectParser,
|
action: parsers.moduleOrObjectParser,
|
||||||
},
|
},
|
||||||
|
redisOptions: {
|
||||||
|
env: 'PARSE_LIVE_QUERY_SERVER_REDIS_OPTIONS',
|
||||||
|
help: "parse-server's LiveQuery redisOptions",
|
||||||
|
action: parsers.objectParser,
|
||||||
|
},
|
||||||
redisURL: {
|
redisURL: {
|
||||||
env: 'PARSE_LIVE_QUERY_SERVER_REDIS_URL',
|
env: 'PARSE_LIVE_QUERY_SERVER_REDIS_URL',
|
||||||
help: "parse-server's LiveQuery redisURL",
|
help: "parse-server's LiveQuery redisURL",
|
||||||
|
|||||||
@@ -76,6 +76,7 @@
|
|||||||
* @interface LiveQueryOptions
|
* @interface LiveQueryOptions
|
||||||
* @property {String[]} classNames parse-server's LiveQuery classNames
|
* @property {String[]} classNames parse-server's LiveQuery classNames
|
||||||
* @property {Adapter<PubSubAdapter>} pubSubAdapter LiveQuery pubsub adapter
|
* @property {Adapter<PubSubAdapter>} pubSubAdapter LiveQuery pubsub adapter
|
||||||
|
* @property {Any} redisOptions parse-server's LiveQuery redisOptions
|
||||||
* @property {String} redisURL parse-server's LiveQuery redisURL
|
* @property {String} redisURL parse-server's LiveQuery redisURL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -88,6 +89,7 @@
|
|||||||
* @property {String} masterKey This string should match the masterKey in use by your Parse Server. If you deploy the LiveQuery server alongside Parse Server, the LiveQuery server will try to use the same masterKey.
|
* @property {String} masterKey This string should match the masterKey in use by your Parse Server. If you deploy the LiveQuery server alongside Parse Server, the LiveQuery server will try to use the same masterKey.
|
||||||
* @property {Number} port The port to run the LiveQuery server, defaults to 1337.
|
* @property {Number} port The port to run the LiveQuery server, defaults to 1337.
|
||||||
* @property {Adapter<PubSubAdapter>} pubSubAdapter LiveQuery pubsub adapter
|
* @property {Adapter<PubSubAdapter>} pubSubAdapter LiveQuery pubsub adapter
|
||||||
|
* @property {Any} redisOptions parse-server's LiveQuery redisOptions
|
||||||
* @property {String} redisURL parse-server's LiveQuery redisURL
|
* @property {String} redisURL parse-server's LiveQuery redisURL
|
||||||
* @property {String} serverURL This string should match the serverURL in use by your Parse Server. If you deploy the LiveQuery server alongside Parse Server, the LiveQuery server will try to use the same serverURL.
|
* @property {String} serverURL This string should match the serverURL in use by your Parse Server. If you deploy the LiveQuery server alongside Parse Server, the LiveQuery server will try to use the same serverURL.
|
||||||
* @property {Number} websocketTimeout Number of milliseconds between ping/pong frames. The WebSocket server sends ping/pong frames to the clients to keep the WebSocket alive. This value defines the interval of the ping/pong frame from the server to clients, defaults to 10 * 1000 ms (10 s).
|
* @property {Number} websocketTimeout Number of milliseconds between ping/pong frames. The WebSocket server sends ping/pong frames to the clients to keep the WebSocket alive. This value defines the interval of the ping/pong frame from the server to clients, defaults to 10 * 1000 ms (10 s).
|
||||||
|
|||||||
@@ -196,6 +196,8 @@ export interface LiveQueryOptions {
|
|||||||
/* parse-server's LiveQuery classNames
|
/* parse-server's LiveQuery classNames
|
||||||
:ENV: PARSE_SERVER_LIVEQUERY_CLASSNAMES */
|
:ENV: PARSE_SERVER_LIVEQUERY_CLASSNAMES */
|
||||||
classNames: ?(string[]);
|
classNames: ?(string[]);
|
||||||
|
/* parse-server's LiveQuery redisOptions */
|
||||||
|
redisOptions: ?any;
|
||||||
/* parse-server's LiveQuery redisURL */
|
/* parse-server's LiveQuery redisURL */
|
||||||
redisURL: ?string;
|
redisURL: ?string;
|
||||||
/* LiveQuery pubsub adapter */
|
/* LiveQuery pubsub adapter */
|
||||||
@@ -220,6 +222,8 @@ export interface LiveQueryServerOptions {
|
|||||||
/* The port to run the LiveQuery server, defaults to 1337.
|
/* The port to run the LiveQuery server, defaults to 1337.
|
||||||
:DEFAULT: 1337 */
|
:DEFAULT: 1337 */
|
||||||
port: ?number;
|
port: ?number;
|
||||||
|
/* parse-server's LiveQuery redisOptions */
|
||||||
|
redisOptions: ?any;
|
||||||
/* parse-server's LiveQuery redisURL */
|
/* parse-server's LiveQuery redisURL */
|
||||||
redisURL: ?string;
|
redisURL: ?string;
|
||||||
/* LiveQuery pubsub adapter */
|
/* LiveQuery pubsub adapter */
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ runner({
|
|||||||
options.liveQuery.redisURL = options['liveQuery.redisURL'];
|
options.liveQuery.redisURL = options['liveQuery.redisURL'];
|
||||||
delete options['liveQuery.redisURL'];
|
delete options['liveQuery.redisURL'];
|
||||||
}
|
}
|
||||||
|
if (options['liveQuery.redisOptions']) {
|
||||||
|
options.liveQuery = options.liveQuery || {};
|
||||||
|
options.liveQuery.redisOptions = options['liveQuery.redisOptions'];
|
||||||
|
delete options['liveQuery.redisOptions'];
|
||||||
|
}
|
||||||
|
|
||||||
if (options.cluster) {
|
if (options.cluster) {
|
||||||
const numCPUs =
|
const numCPUs =
|
||||||
|
|||||||
Reference in New Issue
Block a user