Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {RedisClient} from 'redis';
import * as bluebird from 'bluebird';
bluebird.promisifyAll(RedisClient.prototype);
/* Monkey-patch the module. */
declare module 'redis' {
interface RedisClient {
lpushAsync(key: String, value: string): Promise;
rpoplpushAsync(src: string, dest: string): Promise;
delAsync(src: string): Promise;
}
}
/**
* Object can be converted to a string representation in Redis.
*/
export interface RedisSerializable {
toRedisString(): string;
}
/**
Object.entries(proto).filter(v => typeof v[1] === 'function').forEach(([key, func]) => {
if (proto['p' + key]) return;
proto['p' + key] = function(...args) {
return new Promise((resolve, reject) => {
func.call(this, ...args, (err, res) => {
/* istanbul ignore next */
if (err) reject(err);
else resolve(res);
});
});
};
});
}
promisifyRedisClient(RedisClient.prototype);
module.exports = promisifyRedisClient;