Add types to allow string array argument for hmset (#33835)

* add missing type

* update test

* add name to Definitions By

* add missing types and update test

* regularize formatting

* remove string[]

* remove duplicate typing

* organized formatting

* Merge branch 'master' of https://github.com/OpesanyaAdebayo/DefinitelyTyped

* remove duplicate typing

* add types and tests for typescript 3.0 upwards

* resolve version conflicts

* resolve version conflict

* resolve formatting

* remove new types from older version

* remove header from submodule
This commit is contained in:
onejsninja 2019-03-13 22:48:01 +01:00 committed by Wesley Wigham
parent 0a509d5fb5
commit c00200d2ad
7 changed files with 1419 additions and 4 deletions

View File

@ -10,6 +10,7 @@
// Pirasis Leelatanon <https://github.com/1pete>
// Stanislav Dzhus <https://github.com/blablapolicja>
// Jake Ferrante <https://github.com/ferrantejake>
// Adebayo Opesanya <https://github.com/OpesanyaAdebayo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Imported from: https://github.com/types/npm-redis

11
types/redis/package.json Normal file
View File

@ -0,0 +1,11 @@
{
"private": true,
"types": "index",
"typesVersions": {
">=3.1.0-0": {
"*": [
"ts3.1/*"
]
}
}
}

View File

@ -20,8 +20,8 @@ redis.print(err, value);
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
const options: redis.ClientOpts = {
host: "localhost",
port: 6379,
host: 'localhost',
port: 6379,
};
let client: redis.RedisClient = redis.createClient(num, str, options);
@ -90,6 +90,8 @@ client.incr(str, resCallback);
client.hgetall(str, resCallback);
client.hmset(str, value, okCallback);
client.hmset(str, str, str, str, str, okCallback);
client.hmset(str, [str, str, str, str]);
client.hmset(str, [str, value, str, value], okCallback);
// Publish / Subscribe
client.publish(str, value);
@ -115,8 +117,8 @@ client.duplicate();
// Pipeline
client.cork();
client.set("abc", "fff", strCallback);
client.get("abc", resCallback);
client.set('abc', 'fff', strCallback);
client.get('abc', resCallback);
client.uncork();
// Add command

1235
types/redis/ts3.1/index.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,142 @@
import redis = require('redis');
const value: any = 'any value';
const commandArr: any[][] = [];
const num = 0;
const str = 'any string';
const err: Error = new Error();
const args: any[] = [];
const resCallback: (err: Error | null, res: any) => void = () => {};
const numCallback: (err: Error | null, res: number) => void = () => {};
const strCallback: (err: Error | null, res: string) => void = () => {};
const okCallback: (err: Error | null, res: 'OK') => void = () => {};
const messageHandler: (channel: string, message: any) => void = () => {};
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
const debug_mode: boolean = redis.debug_mode;
redis.print(err, value);
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
const options: redis.ClientOpts = {
host: 'localhost',
port: 6379,
};
let client: redis.RedisClient = redis.createClient(num, str, options);
// Test the `retry_strategy` property
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
function retryStrategyNumber(options: redis.RetryStrategyOptions): number {
// Ensure that the properties of RetryStrategyOptions are resilient to breaking change.
// If the properties of the interface changes, the variables below will also need to be adapted.
const error: Error = options.error;
const total_retry_time: number = options.total_retry_time;
const times_connected: number = options.times_connected;
const attempt: number = options.attempt;
return 5000;
}
function retryStrategyError(options: redis.RetryStrategyOptions): Error {
return new Error('Foo');
}
client = redis.createClient({
retry_strategy: retryStrategyNumber
});
client = redis.createClient({
retry_strategy: retryStrategyError
});
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
const connected: boolean = client.connected;
const retry_delay: number = client.retry_delay;
const retry_backoff: number = client.retry_backoff;
const command_queue: any[] = client.command_queue;
const offline_queue: any[] = client.offline_queue;
const info: redis.ServerInfo = client.server_info;
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
client.end(true);
// Connection (http://redis.io/commands#connection)
client.auth(str, resCallback);
client.ping(strCallback);
client.unref();
// Strings (http://redis.io/commands#strings)
client.append(str, str, numCallback);
client.bitcount(str, numCallback);
client.bitcount(str, num, num, numCallback);
client.set(str, str, okCallback);
client.get(str, strCallback);
client.exists(str, numCallback);
// Event handlers
client.on(str, messageHandler);
client.once(str, messageHandler);
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// some of the bulk methods
client.get('test');
client.get('test', resCallback);
client.set('test', 'test');
client.set('test', 'test', okCallback);
client.mset(args, resCallback);
client.incr(str, resCallback);
// Friendlier hash commands
client.hgetall(str, resCallback);
client.hmset(str, value, okCallback);
client.hmset(str, str, str, str, str, okCallback);
client.hmset([str, str, str, str, str], okCallback);
client.hmset([str, str, str, str, str]);
client.hmset(str, [str, str, str, str]);
client.hmset(str, [str, value, str, value], okCallback);
// Publish / Subscribe
client.publish(str, value);
client.subscribe(str);
// Multi
client.multi()
.scard(str)
.smembers(str)
.keys('*', resCallback)
.dbsize()
.exec(resCallback);
client.multi([['get', 'test']]).exec();
// Monitor mode
client.monitor(resCallback);
// Send command
client.send_command(str, args, resCallback);
// Duplicate
client.duplicate();
// Pipeline
client.cork();
client.set('abc', 'fff', strCallback);
client.get('abc', resCallback);
client.uncork();
// Add command
client.add_command('my command');
client.addCommand('my other command');
// redis.print as callback
client.set(str, str, redis.print);
client.get(str, redis.print);
// increase-by-float reply a string
client.incrbyfloat('a', 1.5, (error, value) => value.startsWith('1'));
client.INCRBYFLOAT('a', 1.5, (error, value) => value.startsWith('1'));
client.hincrbyfloat('a', 'b', 1.5, (error, value) => value.startsWith('1'));
client.HINCRBYFLOAT('a', 'b', 1.5, (error, value) => value.startsWith('1'));
client.zincrby('a', 1, 'b', strCallback);
client.ZINCRBY('a', 1, 'b', strCallback);
client.flushdb(okCallback);

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"redis-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }