mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
Merge pull request #20944 from plantain-00/improve-ioredis-types
improve types of ioredis(add lint)
This commit is contained in:
Vendored
+695
-591
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,13 @@
|
||||
|
||||
|
||||
import * as Redis from "ioredis";
|
||||
var redis = new Redis();
|
||||
const redis = new Redis();
|
||||
|
||||
redis.set('foo', 'bar');
|
||||
redis.get('foo', function(err, result) {
|
||||
redis.get('foo', (err, result) => {
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
// Or using a promise if the last argument isn't a function
|
||||
redis.get('foo').then(function(result: any) {
|
||||
redis.get('foo').then((result: any) => {
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
@@ -18,24 +16,24 @@ redis.sadd('set', 1, 3, 5, 7);
|
||||
redis.sadd('set', [1, 3, 5, 7]);
|
||||
|
||||
// All arguments are passed directly to the redis server:
|
||||
redis.set('key', 100, 'EX', 10);
|
||||
redis.set('key', '100', 'EX', 10);
|
||||
|
||||
new Redis() // Connect to 127.0.0.1:6379
|
||||
new Redis(6380) // 127.0.0.1:6380
|
||||
new Redis(6379, '192.168.1.1') // 192.168.1.1:6379
|
||||
new Redis('/tmp/redis.sock')
|
||||
new Redis(); // Connect to 127.0.0.1:6379
|
||||
new Redis(6380); // 127.0.0.1:6380
|
||||
new Redis(6379, '192.168.1.1'); // 192.168.1.1:6379
|
||||
new Redis('/tmp/redis.sock');
|
||||
new Redis({
|
||||
port: 6379, // Redis port
|
||||
host: '127.0.0.1', // Redis host
|
||||
family: 4, // 4 (IPv4) or 6 (IPv6)
|
||||
password: 'auth',
|
||||
db: 0,
|
||||
retryStrategy: function() { return false; },
|
||||
retryStrategy() { return false; },
|
||||
showFriendlyErrorStack: true
|
||||
})
|
||||
});
|
||||
|
||||
var pub = new Redis();
|
||||
redis.subscribe('news', 'music', function(err: any, count: any) {
|
||||
const pub = new Redis();
|
||||
redis.subscribe('news', 'music', (err: any, count: any) => {
|
||||
// Now we are subscribed to both the 'news' and 'music' channels.
|
||||
// `count` represents the number of channels we are currently subscribed to.
|
||||
|
||||
@@ -43,7 +41,7 @@ redis.subscribe('news', 'music', function(err: any, count: any) {
|
||||
pub.publish('music', 'Hello again!');
|
||||
});
|
||||
|
||||
redis.on('message', function(channel: any, message: any) {
|
||||
redis.on('message', (channel: any, message: any) => {
|
||||
// Receive message Hello world! from channel news
|
||||
// Receive message Hello again! from channel music
|
||||
console.log('Receive message %s from channel %s', message, channel);
|
||||
@@ -51,6 +49,44 @@ redis.on('message', function(channel: any, message: any) {
|
||||
|
||||
// There's also an event called 'messageBuffer', which is the same as 'message' except
|
||||
// it returns buffers instead of strings.
|
||||
redis.on('messageBuffer', function(channel: any, message: any) {
|
||||
redis.on('messageBuffer', (channel: any, message: any) => {
|
||||
// Both `channel` and `message` are buffers.
|
||||
});
|
||||
|
||||
const pipeline = redis.pipeline();
|
||||
pipeline.set('foo', 'bar');
|
||||
pipeline.del('cc');
|
||||
pipeline.exec((err, results) => {
|
||||
// `err` is always null, and `results` is an array of responses
|
||||
// corresponding to the sequence of queued commands.
|
||||
// Each response follows the format `[err, result]`.
|
||||
});
|
||||
|
||||
// You can even chain the commands:
|
||||
redis.pipeline().set('foo', 'bar').del('cc').exec((err, results) => {
|
||||
});
|
||||
|
||||
// `exec` also returns a Promise:
|
||||
const promise = redis.pipeline().set('foo', 'bar').get('foo').exec();
|
||||
promise.then((result) => {
|
||||
// result === [[null, 'OK'], [null, 'bar']]
|
||||
});
|
||||
|
||||
redis.pipeline().set('foo', 'bar').get('foo', (err, result) => {
|
||||
// result === 'bar'
|
||||
}).exec((err, result) => {
|
||||
// result[1][1] === 'bar'
|
||||
});
|
||||
|
||||
redis.pipeline([
|
||||
['set', 'foo', 'bar'],
|
||||
['get', 'foo']
|
||||
]).exec(() => { /* ... */ });
|
||||
|
||||
Redis.Command.setArgumentTransformer('set', args => {
|
||||
return args;
|
||||
});
|
||||
|
||||
Redis.Command.setReplyTransformer('get', (result: any) => {
|
||||
return result;
|
||||
});
|
||||
|
||||
@@ -1,79 +1 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
|
||||
Reference in New Issue
Block a user