-
Notifications
You must be signed in to change notification settings - Fork 4
/
examples.js
52 lines (43 loc) · 1.21 KB
/
examples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var sys = require("sys"),
redislib = require("redis"),
redis = redislib.createClient(),
redis2json = require("./lib/redis2json");
var map = {
postId: ":{postId}",
text: "post:{postId}:text",
created: "post:{postId}:created",
$authorId: "post:{postId}:author",
author: {
authorId: ":{authorId}",
username: "user:{authorId}:username",
password: "user:{authorId}:password"
},
$$comments: { variable: "commentId", cmd: "lrange", key: "post:{postId}:comments", args: [0, 20] },
comments: [
{
commentId: ":{commentId}",
text: "comment:{commentId}:text",
created: "comment:{commentId}:create",
$commentAuthorId: "comment:{commentId}:author",
author: {
authorId: ":{commentAuthorId}",
username: "user:{commentAuthorId}:username",
password: "user:{commentAuthorId}:password"
}
}
]
};
map = {
$$posts: { variable: "postId", cmd: "lrange", key: "posts", args: [0, 30] },
posts: [ map ]
};
var variables = {
postId: 1
};
redis2json.load(map, variables, function (error, object) {
if (error) {
sys.debug("LOADED ERROR: " + error + "; OBJ: " + sys.inspect(object, false, 10));
} else {
sys.debug("LOADED: " + sys.inspect(object, false, 10));
}
});