LiveQuery: Add options for Redis (#5584)

Closes: https://github.com/parse-community/parse-server/issues/5387
This commit is contained in:
Diamond Lewis
2019-05-11 19:13:41 -05:00
committed by GitHub
parent b9c936f594
commit 0ce4eeae72
7 changed files with 41 additions and 6 deletions

View File

@@ -28,6 +28,7 @@ describe('ParsePubSub', function() {
it('can create redis publisher', function() {
ParsePubSub.createPublisher({
redisURL: 'redisURL',
redisOptions: { socket_keepalive: true },
});
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub')
@@ -36,6 +37,7 @@ describe('ParsePubSub', function() {
.EventEmitterPubSub;
expect(RedisPubSub.createPublisher).toHaveBeenCalledWith({
redisURL: 'redisURL',
redisOptions: { socket_keepalive: true },
});
expect(EventEmitterPubSub.createPublisher).not.toHaveBeenCalled();
});
@@ -54,6 +56,7 @@ describe('ParsePubSub', function() {
it('can create redis subscriber', function() {
ParsePubSub.createSubscriber({
redisURL: 'redisURL',
redisOptions: { socket_keepalive: true },
});
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub')
@@ -62,6 +65,7 @@ describe('ParsePubSub', function() {
.EventEmitterPubSub;
expect(RedisPubSub.createSubscriber).toHaveBeenCalledWith({
redisURL: 'redisURL',
redisOptions: { socket_keepalive: true },
});
expect(EventEmitterPubSub.createSubscriber).not.toHaveBeenCalled();
});

View File

@@ -9,19 +9,27 @@ describe('RedisPubSub', function() {
});
it('can create publisher', function() {
RedisPubSub.createPublisher({ redisURL: 'redisAddress' });
RedisPubSub.createPublisher({
redisURL: 'redisAddress',
redisOptions: { socket_keepalive: true },
});
const redis = require('redis');
expect(redis.createClient).toHaveBeenCalledWith('redisAddress', {
socket_keepalive: true,
no_ready_check: true,
});
});
it('can create subscriber', function() {
RedisPubSub.createSubscriber({ redisURL: 'redisAddress' });
RedisPubSub.createSubscriber({
redisURL: 'redisAddress',
redisOptions: { socket_keepalive: true },
});
const redis = require('redis');
expect(redis.createClient).toHaveBeenCalledWith('redisAddress', {
socket_keepalive: true,
no_ready_check: true,
});
});

View File

@@ -1,11 +1,13 @@
import redis from 'redis';
function createPublisher({ redisURL }): any {
return redis.createClient(redisURL, { no_ready_check: true });
function createPublisher({ redisURL, redisOptions = {} }): any {
redisOptions.no_ready_check = true;
return redis.createClient(redisURL, redisOptions);
}
function createSubscriber({ redisURL }): any {
return redis.createClient(redisURL, { no_ready_check: true });
function createSubscriber({ redisURL, redisOptions = {} }): any {
redisOptions.no_ready_check = true;
return redis.createClient(redisURL, redisOptions);
}
const RedisPubSub = {

View File

@@ -377,6 +377,11 @@ module.exports.LiveQueryOptions = {
help: 'LiveQuery pubsub adapter',
action: parsers.moduleOrObjectParser,
},
redisOptions: {
env: 'PARSE_SERVER_LIVEQUERY_REDIS_OPTIONS',
help: "parse-server's LiveQuery redisOptions",
action: parsers.objectParser,
},
redisURL: {
env: 'PARSE_SERVER_LIVEQUERY_REDIS_URL',
help: "parse-server's LiveQuery redisURL",
@@ -421,6 +426,11 @@ module.exports.LiveQueryServerOptions = {
help: 'LiveQuery pubsub adapter',
action: parsers.moduleOrObjectParser,
},
redisOptions: {
env: 'PARSE_LIVE_QUERY_SERVER_REDIS_OPTIONS',
help: "parse-server's LiveQuery redisOptions",
action: parsers.objectParser,
},
redisURL: {
env: 'PARSE_LIVE_QUERY_SERVER_REDIS_URL',
help: "parse-server's LiveQuery redisURL",

View File

@@ -76,6 +76,7 @@
* @interface LiveQueryOptions
* @property {String[]} classNames parse-server's LiveQuery classNames
* @property {Adapter<PubSubAdapter>} pubSubAdapter LiveQuery pubsub adapter
* @property {Any} redisOptions parse-server's LiveQuery redisOptions
* @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 {Number} port The port to run the LiveQuery server, defaults to 1337.
* @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} 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).

View File

@@ -196,6 +196,8 @@ export interface LiveQueryOptions {
/* parse-server's LiveQuery classNames
:ENV: PARSE_SERVER_LIVEQUERY_CLASSNAMES */
classNames: ?(string[]);
/* parse-server's LiveQuery redisOptions */
redisOptions: ?any;
/* parse-server's LiveQuery redisURL */
redisURL: ?string;
/* LiveQuery pubsub adapter */
@@ -220,6 +222,8 @@ export interface LiveQueryServerOptions {
/* The port to run the LiveQuery server, defaults to 1337.
:DEFAULT: 1337 */
port: ?number;
/* parse-server's LiveQuery redisOptions */
redisOptions: ?any;
/* parse-server's LiveQuery redisURL */
redisURL: ?string;
/* LiveQuery pubsub adapter */

View File

@@ -60,6 +60,11 @@ runner({
options.liveQuery.redisURL = 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) {
const numCPUs =