mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add redis-scripto typings with tests.
This commit is contained in:
parent
3a056e3864
commit
b7802eae32
37
redis-scripto/redis-scripto-tests.ts
Normal file
37
redis-scripto/redis-scripto-tests.ts
Normal file
@ -0,0 +1,37 @@
|
||||
/// <reference path="../redis/redis.d.ts" />
|
||||
/// <reference path="redis-scripto.d.ts" />
|
||||
|
||||
import * as redis from 'redis';
|
||||
import * as Scripto from 'redis-scripto';
|
||||
|
||||
var num: number;
|
||||
var str: string;
|
||||
var options: redis.ClientOpts;
|
||||
var redisClient = redis.createClient(num, str, options);
|
||||
|
||||
var scriptManager = new Scripto(redisClient);
|
||||
scriptManager.loadFromDir('/path/to/lua/scripts');
|
||||
|
||||
var keys = ['keyOne', 'keyTwo'];
|
||||
var values = [10, 20];
|
||||
scriptManager.run('your-script', keys, values, function(err, result) {
|
||||
|
||||
});
|
||||
|
||||
scriptManager.eval('your-script', keys, values, function(err, result) {
|
||||
|
||||
});
|
||||
|
||||
scriptManager.loadFromFile('script-one', '/path/to/the/file');
|
||||
scriptManager.run('script-one', [], [], function(err, result) {
|
||||
|
||||
});
|
||||
|
||||
var scripts: Scripto.Scripts = {
|
||||
'script-two': 'return 1000'
|
||||
};
|
||||
|
||||
scriptManager.load(scripts);
|
||||
scriptManager.run('script-two', [], [], function(err, result) {
|
||||
|
||||
});
|
||||
39
redis-scripto/redis-scripto.d.ts
vendored
Normal file
39
redis-scripto/redis-scripto.d.ts
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
// Type definitions for redis-scripto 0.1.3
|
||||
// Project: https://github.com/arunoda/node-redis-scripto
|
||||
// Definitions by: Seth Westphal <https://github.com/westy92>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../redis/redis.d.ts" />
|
||||
|
||||
declare module "redis-scripto" {
|
||||
|
||||
import * as redis from 'redis';
|
||||
|
||||
class Scripto {
|
||||
|
||||
constructor(redisClient: redis.RedisClient);
|
||||
|
||||
eval(scriptName: string, keys: string[], args: any[], callback: (err: Error, result: any) => void): void;
|
||||
evalSha(scriptName: string, keys: string[], args: any[], callback: (err: Error, result: any) => void): void;
|
||||
|
||||
load(scripts: Scripto.Scripts): void;
|
||||
loadFromDir(scriptsDir: string): void;
|
||||
loadFromFile(name: string, filepath: string): void;
|
||||
|
||||
run(scriptName: string, keys: string[], args: any[], callback: (err: Error, result: any) => void): void;
|
||||
|
||||
}
|
||||
|
||||
namespace Scripto {
|
||||
|
||||
export type Script = string;
|
||||
|
||||
export interface Scripts {
|
||||
[scriptName: string]: Script;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export = Scripto;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user