mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 06:50:19 +00:00
node_redis definitions and tests added
This commit is contained in:
Vendored
+349
@@ -0,0 +1,349 @@
|
||||
// Type definitions for node_redis 0.8
|
||||
// Project: https://github.com/mranney/node_redis
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module 'redis' {
|
||||
export var debug_mode: bool;
|
||||
export function createClient(): RedisClient;
|
||||
export function createClient(port: string, host: string, options: RedisOptions): RedisClient;
|
||||
export function print(err: string, reply?: string);
|
||||
|
||||
interface RedisOptions {
|
||||
parser: string;
|
||||
return_buffers: bool;
|
||||
detect_buffers: bool;
|
||||
socket_nodelay: bool;
|
||||
no_ready_check: bool;
|
||||
enable_offline_queue: bool;
|
||||
}
|
||||
|
||||
interface Command {
|
||||
(...args: any[], callback?: Function): Commands;
|
||||
}
|
||||
|
||||
interface Commands {
|
||||
|
||||
get: Command;
|
||||
set: Command;
|
||||
setnx: Command;
|
||||
setex: Command;
|
||||
append: Command;
|
||||
strlen: Command;
|
||||
del: Command;
|
||||
exists: Command;
|
||||
setbit: Command;
|
||||
getbit: Command;
|
||||
setrange: Command;
|
||||
getrange: Command;
|
||||
substr: Command;
|
||||
incr: Command;
|
||||
decr: Command;
|
||||
mget: Command;
|
||||
|
||||
rpush: Command;
|
||||
lpush: Command;
|
||||
rpushx: Command;
|
||||
lpushx: Command;
|
||||
linsert: Command;
|
||||
rpop: Command;
|
||||
lpop: Command;
|
||||
brpop: Command;
|
||||
brpoplpush: Command;
|
||||
blpop: Command;
|
||||
llen: Command;
|
||||
lindex: Command;
|
||||
lset: Command;
|
||||
lrange: Command;
|
||||
ltrim: Command;
|
||||
lrem: Command;
|
||||
rpoplpush: Command;
|
||||
|
||||
sadd: Command;
|
||||
srem: Command;
|
||||
smove: Command;
|
||||
sismember: Command;
|
||||
scard: Command;
|
||||
spop: Command;
|
||||
srandmember: Command;
|
||||
sinter: Command;
|
||||
sinterstore: Command;
|
||||
sunion: Command;
|
||||
sunionstore: Command;
|
||||
sdiff: Command;
|
||||
sdiffstore: Command;
|
||||
smembers: Command;
|
||||
|
||||
zadd: Command;
|
||||
zincrby: Command;
|
||||
zrem: Command;
|
||||
zremrangebyscore: Command;
|
||||
zremrangebyrank: Command;
|
||||
zunionstore: Command;
|
||||
zinterstore: Command;
|
||||
zrange: Command;
|
||||
zrangebyscore: Command;
|
||||
zrevrangebyscore: Command;
|
||||
zcount: Command;
|
||||
zrevrange: Command;
|
||||
zcard: Command;
|
||||
zscore: Command;
|
||||
zrank: Command;
|
||||
zrevrank: Command;
|
||||
|
||||
hset: Command;
|
||||
hsetnx: Command;
|
||||
hget: Command;
|
||||
hmset: Command;
|
||||
hmget: Command;
|
||||
hincrby: Command;
|
||||
hdel: Command;
|
||||
hlen: Command;
|
||||
hkeys: Command;
|
||||
hvals: Command;
|
||||
hgetall: Command;
|
||||
hexists: Command;
|
||||
|
||||
incrby: Command;
|
||||
decrby: Command;
|
||||
getset: Command;
|
||||
mset: Command;
|
||||
msetnx: Command;
|
||||
randomkey: Command;
|
||||
select: Command;
|
||||
move: Command;
|
||||
rename: Command;
|
||||
renamenx: Command;
|
||||
expire: Command;
|
||||
expireat: Command;
|
||||
keys: Command;
|
||||
dbsize: Command;
|
||||
auth: Command;
|
||||
ping: Command;
|
||||
echo: Command;
|
||||
save: Command;
|
||||
bgsave: Command;
|
||||
bgrewriteaof: Command;
|
||||
shutdown: Command;
|
||||
lastsave: Command;
|
||||
type: Command;
|
||||
multi: Command;
|
||||
exec: Command;
|
||||
discard: Command;
|
||||
sync: Command;
|
||||
flushdb: Command;
|
||||
flushall: Command;
|
||||
sort: Command;
|
||||
info: Command;
|
||||
monitor: Command;
|
||||
ttl: Command;
|
||||
persist: Command;
|
||||
slaveof: Command;
|
||||
debug: Command;
|
||||
config: Command;
|
||||
subscribe: Command;
|
||||
unsubscribe: Command;
|
||||
psubscribe: Command;
|
||||
punsubscribe: Command;
|
||||
publish: Command;
|
||||
watch: Command;
|
||||
unwatch: Command;
|
||||
cluster: Command;
|
||||
restore: Command;
|
||||
migrate: Command;
|
||||
dump: Command;
|
||||
object: Command;
|
||||
client: Command;
|
||||
eval: Command;
|
||||
evalsha: Command;
|
||||
|
||||
/////////////////
|
||||
|
||||
GET: Command;
|
||||
SET: Command;
|
||||
SETNX: Command;
|
||||
SETEX: Command;
|
||||
APPEND: Command;
|
||||
STRLEN: Command;
|
||||
DEL: Command;
|
||||
EXISTS: Command;
|
||||
SETBIT: Command;
|
||||
GETBIT: Command;
|
||||
SETRANGE: Command;
|
||||
GETRANGE: Command;
|
||||
SUBSTR: Command;
|
||||
INCR: Command;
|
||||
DECR: Command;
|
||||
MGET: Command;
|
||||
|
||||
RPUSH: Command;
|
||||
LPUSH: Command;
|
||||
RPUSHX: Command;
|
||||
LPUSHX: Command;
|
||||
LINSERT: Command;
|
||||
RPOP: Command;
|
||||
LPOP: Command;
|
||||
BRPOP: Command;
|
||||
BRPOPLPUSH: Command;
|
||||
BLPOP: Command;
|
||||
LLEN: Command;
|
||||
LINDEX: Command;
|
||||
LSET: Command;
|
||||
LRANGE: Command;
|
||||
LTRIM: Command;
|
||||
LREM: Command;
|
||||
RPOPLPUSH: Command;
|
||||
|
||||
SADD: Command;
|
||||
SREM: Command;
|
||||
SMOVE: Command;
|
||||
SISMEMBER: Command;
|
||||
SCARD: Command;
|
||||
SPOP: Command;
|
||||
SRANDMEMBER: Command;
|
||||
SINTER: Command;
|
||||
SINTERSTORE: Command;
|
||||
SUNION: Command;
|
||||
SUNIONSTORE: Command;
|
||||
SDIFF: Command;
|
||||
SDIFFSTORE: Command;
|
||||
SMEMBERS: Command;
|
||||
|
||||
ZADD: Command;
|
||||
ZINCRBY: Command;
|
||||
ZREM: Command;
|
||||
ZREMRANGEBYSCORE: Command;
|
||||
ZREMRANGEBYRANK: Command;
|
||||
ZUNIONSTORE: Command;
|
||||
ZINTERSTORE: Command;
|
||||
ZRANGE: Command;
|
||||
ZRANGEBYSCORE: Command;
|
||||
ZREVRANGEBYSCORE: Command;
|
||||
ZCOUNT: Command;
|
||||
ZREVRANGE: Command;
|
||||
ZCARD: Command;
|
||||
ZSCORE: Command;
|
||||
ZRANK: Command;
|
||||
ZREVRANK: Command;
|
||||
|
||||
HSET: Command;
|
||||
HSETNX: Command;
|
||||
HGET: Command;
|
||||
HMSET: Command;
|
||||
HMGET: Command;
|
||||
HINCRBY: Command;
|
||||
HDEL: Command;
|
||||
HLEN: Command;
|
||||
HKEYS: Command;
|
||||
HVALS: Command;
|
||||
HGETALL: Command;
|
||||
HEXISTS: Command;
|
||||
|
||||
INCRBY: Command;
|
||||
DECRBY: Command;
|
||||
GETSET: Command;
|
||||
MSET: Command;
|
||||
MSETNX: Command;
|
||||
RANDOMKEY: Command;
|
||||
SELECT: Command;
|
||||
MOVE: Command;
|
||||
RENAME: Command;
|
||||
RENAMENX: Command;
|
||||
EXPIRE: Command;
|
||||
EXPIREAT: Command;
|
||||
KEYS: Command;
|
||||
DBSIZE: Command;
|
||||
AUTH: Command;
|
||||
PING: Command;
|
||||
ECHO: Command;
|
||||
SAVE: Command;
|
||||
BGSAVE: Command;
|
||||
BGREWRITEAOF: Command;
|
||||
SHUTDOWN: Command;
|
||||
LASTSAVE: Command;
|
||||
TYPE: Command;
|
||||
MULTI: Command;
|
||||
EXEC: Command;
|
||||
DISCARD: Command;
|
||||
SYNC: Command;
|
||||
FLUSHDB: Command;
|
||||
FLUSHALL: Command;
|
||||
SORT: Command;
|
||||
INFO: Command;
|
||||
MONITOR: Command;
|
||||
TTL: Command;
|
||||
PERSIST: Command;
|
||||
SLAVEOF: Command;
|
||||
DEBUG: Command;
|
||||
CONFIG: Command;
|
||||
SUBSCRIBE: Command;
|
||||
UNSUBSCRIBE: Command;
|
||||
PSUBSCRIBE: Command;
|
||||
PUNSUBSCRIBE: Command;
|
||||
PUBLISH: Command;
|
||||
WATCH: Command;
|
||||
UNWATCH: Command;
|
||||
CLUSTER: Command;
|
||||
RESTORE: Command;
|
||||
MIGRATE: Command;
|
||||
DUMP: Command;
|
||||
OBJECT: Command;
|
||||
CLIENT: Command;
|
||||
EVAL: Command;
|
||||
EVALSHA: Command;
|
||||
|
||||
|
||||
hgetall(hash);
|
||||
hmset(hash, obj, callback?: Function);
|
||||
hmset(hash, key1, val1, ... keyn, valn, [callback])
|
||||
|
||||
hmset(args, callback: Function);
|
||||
HMGET (args, callback: Function);
|
||||
}
|
||||
|
||||
interface Multi extends Commands {
|
||||
exec(callback: Function, ...commands: any[]): void;
|
||||
EXEC(callback: Function, ...commands: any[]): void;
|
||||
}
|
||||
|
||||
interface RedisClient extends Commands {
|
||||
|
||||
initialize_retry_vars(): void;
|
||||
flush_and_error(message: string): void;
|
||||
on_error(message: string): void;
|
||||
do_auth(): void;
|
||||
on_connect(): void;
|
||||
init_parser(): void;
|
||||
on_ready(): void;
|
||||
on_info_cmd(err, res): void;
|
||||
ready_check(): void;
|
||||
send_offline_queue(): void;
|
||||
connection_gone(why: string): void;
|
||||
on_data(data): void;
|
||||
return_error(err): void;
|
||||
return_reply(reply): void;
|
||||
send_command(command: string, args: any[], callback?: Function);
|
||||
send_command(command: string, ...args: any[], callback?: Function);
|
||||
pub_sub_command(command: { command: string; args: any[]; });
|
||||
|
||||
eval(): void;
|
||||
|
||||
server_info;
|
||||
connected: bool;
|
||||
command_queue: any[];
|
||||
offline_queue: any[];
|
||||
retry_delay : number;
|
||||
retry_backoff: number;
|
||||
|
||||
auth(password: string, callback: Function): void;
|
||||
AUTH(password: string, callback: Function): void;
|
||||
|
||||
end(): RedisClient;
|
||||
|
||||
on("subscribe", (channel, count) => void); // +emit
|
||||
|
||||
send_command(command_name, args, callback)
|
||||
|
||||
multi(...commands: any[]): Multi;
|
||||
MULTI(...commands: any[]): Multi;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ Complete
|
||||
* [Moment.js](https://github.com/timrwood/moment) (by [Michael Lakerveld](https://github.com/Lakerfield))
|
||||
* [Mustache.js](https://github.com/janl/mustache.js)
|
||||
* [Node.js](http://nodejs.org/) (from TypeScript samples)
|
||||
* [node_redis](https://github.com/mranney/node_redis)
|
||||
* [QUnit](http://qunitjs.com/) (by [Diullei Gomes](https://github.com/Diullei))
|
||||
* [Raphael](http://raphaeljs.com/) (by [CheCoxshall](https://github.com/CheCoxshall))
|
||||
* [Spin](http://fgnass.github.com/spin.js/)
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/// <reference path="../Definitions/node_redis-0.8.d.ts" />
|
||||
|
||||
import redis = module('redis');
|
||||
|
||||
function test1() {
|
||||
var client = redis.createClient();
|
||||
|
||||
client.on("error", function (err) {
|
||||
console.log("Error " + err);
|
||||
});
|
||||
|
||||
client.set("string key", "string val", redis.print);
|
||||
client.hset("hash key", "hashtest 1", "some value", redis.print);
|
||||
client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
|
||||
client.hkeys("hash key", (err, replies) => {
|
||||
console.log(replies.length + " replies:");
|
||||
replies.forEach((reply, i) => {
|
||||
console.log(" " + i + ": " + reply);
|
||||
});
|
||||
client.quit();
|
||||
});
|
||||
|
||||
client.mset(["test keys 1", "test val 1", "test keys 2", "test val 2"], function (err, res) { });
|
||||
client.mset("test keys 1", "test val 1", "test keys 2", "test val 2", function (err, res) { });
|
||||
client.set("some key", "some val");
|
||||
client.set(["some other key", "some val"]);
|
||||
client.get("missingkey", (err, reply) => { });
|
||||
}
|
||||
|
||||
function test2() { {
|
||||
var client = redis.createClient(null, null, {
|
||||
detect_buffers: true
|
||||
});
|
||||
|
||||
client.set("foo_rand000000000000", "OK");
|
||||
client.get("foo_rand000000000000", (err, reply) => {
|
||||
console.log(reply.toString());
|
||||
});
|
||||
client.get(new Buffer("foo_rand000000000000"), (err, reply) => {
|
||||
console.log(reply.toString());
|
||||
});
|
||||
client.end();
|
||||
}
|
||||
|
||||
function test3() {
|
||||
var client = redis.createClient();
|
||||
|
||||
client.set("foo_rand000000000000", "some fantastic value");
|
||||
client.get("foo_rand000000000000", (err, reply) => {
|
||||
console.log(reply.toString());
|
||||
});
|
||||
client.end();
|
||||
|
||||
client.hmset("hosts", "mjr", "1", "another", "23", "home", "1234");
|
||||
client.hgetall("hosts", function (err, obj) {
|
||||
console.dir(obj);
|
||||
});
|
||||
|
||||
client.HMSET(key2, {
|
||||
"0123456789": "abcdefghij", // NOTE: the key and value must both be strings
|
||||
"some manner of key": "a type of value"
|
||||
});
|
||||
|
||||
client.HMSET(key1, "0123456789", "abcdefghij", "some manner of key", "a type of value");
|
||||
}
|
||||
|
||||
function test4() {
|
||||
var client1 = redis.createClient(), client2 = redis.createClient(),
|
||||
msg_count = 0;
|
||||
|
||||
client1.on("subscribe", function (channel, count) {
|
||||
client2.publish("a nice channel", "I am sending a message.");
|
||||
client2.publish("a nice channel", "I am sending a second message.");
|
||||
client2.publish("a nice channel", "I am sending my last message.");
|
||||
});
|
||||
|
||||
client1.on("message", function (channel, message) {
|
||||
console.log("client1 channel " +channel + ": " +message);
|
||||
msg_count += 1;
|
||||
if(msg_count === 3) {
|
||||
client1.unsubscribe();
|
||||
client1.end();
|
||||
client2.end();
|
||||
}});
|
||||
|
||||
client1.incr("did a thing");
|
||||
client1.subscribe("a nice channel");
|
||||
}
|
||||
|
||||
function test5() {
|
||||
var client = redis.createClient(), set_size = 20;
|
||||
|
||||
client.sadd("bigset", "a member");
|
||||
client.sadd("bigset", "another member");
|
||||
|
||||
while (set_size > 0) {
|
||||
client.sadd("bigset", "member " + set_size);
|
||||
set_size -= 1;
|
||||
}
|
||||
|
||||
client.multi()
|
||||
.scard("bigset")
|
||||
.smembers("bigset")
|
||||
.keys("*", function (err, replies) {
|
||||
client.mget(replies, redis.print);
|
||||
})
|
||||
.dbsize()
|
||||
.exec(function (err, replies) {
|
||||
console.log("MULTI got " + replies.length + " replies");
|
||||
replies.forEach(function (reply, index) {
|
||||
console.log("Reply " + index + ": " + reply.toString());
|
||||
});
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
function test6() {
|
||||
var client = redis.createClient(), multi;
|
||||
|
||||
multi = client.multi();
|
||||
multi.incr("incr thing", redis.print);
|
||||
multi.incr("incr other thing", redis.print);
|
||||
|
||||
client.mset("incr thing", 100, "incr other thing", 1, redis.print);
|
||||
|
||||
multi.exec(function (err, replies) {
|
||||
console.log(replies);
|
||||
});
|
||||
|
||||
multi.exec(function (err, replies) {
|
||||
console.log(replies);
|
||||
client.quit();
|
||||
});
|
||||
}
|
||||
|
||||
function test7() {
|
||||
var client = redis.createClient(), multi;
|
||||
|
||||
client.multi([
|
||||
["mget", "multifoo", "multibar", redis.print],
|
||||
["incr", "multifoo"],
|
||||
["incr", "multibar"]
|
||||
]).exec(function (err, replies) {
|
||||
console.log(replies);
|
||||
});
|
||||
}
|
||||
|
||||
function test8() {
|
||||
var util = require("util");
|
||||
|
||||
client.monitor(function (err, res) {
|
||||
console.log("Entering monitoring mode.");
|
||||
});
|
||||
|
||||
client.on("monitor", function (time, args) {
|
||||
console.log(time + ": " +util.inspect(args));
|
||||
});
|
||||
}
|
||||
|
||||
function test9() {
|
||||
var client = redis.createClient();
|
||||
|
||||
client.on("connect", function () {
|
||||
client.set("foo_rand000000000000", "some fantastic value", redis.print);
|
||||
client.get("foo_rand000000000000", redis.print);
|
||||
});
|
||||
}
|
||||
|
||||
function test10() {
|
||||
var client = redis.createClient();
|
||||
|
||||
redis.debug_mode = true;
|
||||
|
||||
client.on("connect", function () {
|
||||
client.set("foo_rand000000000000", "some fantastic value");
|
||||
});
|
||||
|
||||
var args = ['myzset', 1, 'one', 2, 'two', 3, 'three', 99, 'ninety-nine'];
|
||||
client.zadd(args, function (err, response) {
|
||||
if (err) throw err;
|
||||
console.log('added ' + response + ' items.');
|
||||
|
||||
var args1 = ['myzset', '+inf', '-inf'];
|
||||
client.zrevrangebyscore(args1, function (err, response) {
|
||||
if (err) throw err;
|
||||
console.log('example1', response);
|
||||
});
|
||||
|
||||
var max = 3, min = 1, offset = 1, count = 2;
|
||||
var args2 = ['myzset', max, min, 'WITHSCORES', 'LIMIT', offset, count];
|
||||
client.zrevrangebyscore(args2, function (err, response) {
|
||||
if (err) throw err;
|
||||
console.log('example2', response);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user