UNPKG

3.98 kBJavaScriptView Raw
1/*
2 * Copyright (c) 2012 Dmitri Melikyan
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to permit
9 * persons to whom the Software is furnished to do so, subject to the
10 * following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25var nt = require('../nodetime');
26var proxy = require('../proxy');
27var samples = require('../samples');
28
29var commands = [
30 "append",
31 "auth",
32 "bgrewriteaof",
33 "bgsave",
34 "blpop",
35 "brpop",
36 "brpoplpush",
37 "config get",
38 "config set",
39 "config resetstat",
40 "dbsize",
41 "debug object",
42 "debug segfault",
43 "decr",
44 "decrby",
45 "del",
46 "discard",
47 "echo",
48 "exec",
49 "exists",
50 "expire",
51 "expireat",
52 "flushall",
53 "flushdb",
54 "get",
55 "getbit",
56 "getrange",
57 "getset",
58 "hdel",
59 "hexists",
60 "hget",
61 "hgetall",
62 "hincrby",
63 "hkeys",
64 "hlen",
65 "hmget",
66 "hmset",
67 "hset",
68 "hsetnx",
69 "hvals",
70 "incr",
71 "incrby",
72 "info",
73 "keys",
74 "lastsave",
75 "lindex",
76 "linsert",
77 "llen",
78 "lpop",
79 "lpush",
80 "lpushx",
81 "lrange",
82 "lrem",
83 "lset",
84 "ltrim",
85 "mget",
86 "monitor",
87 "move",
88 "mset",
89 "msetnx",
90 "multi",
91 "object",
92 "persist",
93 "ping",
94 "psubscribe",
95 "publish",
96 "punsubscribe",
97 "quit",
98 "randomkey",
99 "rename",
100 "renamenx",
101 "rpop",
102 "rpoplpush",
103 "rpush",
104 "rpushx",
105 "sadd",
106 "save",
107 "scard",
108 "sdiff",
109 "sdiffstore",
110 "select",
111 "set",
112 "setbit",
113 "setex",
114 "setnx",
115 "setrange",
116 "shutdown",
117 "sinter",
118 "sinterstore",
119 "sismember",
120 "slaveof",
121 "smembers",
122 "smove",
123 "sort",
124 "spop",
125 "srandmember",
126 "srem",
127 "strlen",
128 "subscribe",
129 "sunion",
130 "sunionstore",
131 "sync",
132 "ttl",
133 "type",
134 "unsubscribe",
135 "unwatch",
136 "watch",
137 "zadd",
138 "zcard",
139 "zcount",
140 "zincrby",
141 "zinterstore",
142 "zrange",
143 "zrangebyscore",
144 "zrank",
145 "zrem",
146 "zremrangebyrank",
147 "zremrangebyscore",
148 "zrevrange",
149 "zrevrangebyscore",
150 "zrevrank",
151 "zscore",
152 "zunionstore"
153];
154
155
156module.exports = function(obj) {
157 proxy.after(obj, 'createClient', function(obj, args, ret) {
158 var client = ret;
159 commands.forEach(function(command) {
160 proxy.before(ret, command, function(obj, args) {
161 var trace = samples.stackTrace();
162 var time = samples.time("Redis", command);
163 var params = args;
164
165 proxy.callback(args, -1, function(obj, args) {
166 if(!time.done()) return;
167 if(nt.paused) return;
168
169 var error = (args && args.length > 0) ? (args[0] ? args[0].message : undefined) : undefined;
170 var obj = {'Type': 'Redis',
171 'Connection': {host: client.host, port: client.port},
172 'Command': command,
173 'Arguments': samples.truncate(params),
174 'Stack trace': trace,
175 'Error': error};
176
177 samples.add(time, obj, 'Redis: ' + command);
178 });
179 });
180 });
181 });
182};
183