model-redis 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
# Model Redis
|
|
2
2
|
|
|
3
|
-
Simple ORM model for
|
|
4
|
-
This provides a simple ORM interface, with schema, for
|
|
3
|
+
Simple ORM model for Redis in NodsJS. The only external dependence is `redis`.
|
|
4
|
+
This provides a simple ORM interface, with schema, for Redis. This is not meant
|
|
5
5
|
for large data sets and is geared more for small, internal infrastructure based
|
|
6
6
|
projects that do not require complex data model.
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
## Getting started
|
|
10
10
|
|
|
11
|
-
`setUpTable([object])` -- *Function* to bind the
|
|
11
|
+
`setUpTable([object])` -- *Function* to bind the Redis connection
|
|
12
12
|
object to the ORM table. It takes an optional connected redis client object
|
|
13
|
-
or configuration for the
|
|
13
|
+
or configuration for the Redis module. This will return a `Table` class we
|
|
14
14
|
can use later for our model.
|
|
15
15
|
|
|
16
16
|
It is recommend you place this in a utility or lib file with in your project
|
|
17
17
|
and require it when needed.
|
|
18
18
|
|
|
19
19
|
The simplest way to use this is to pass nothing to the `setUpTable` function.
|
|
20
|
-
this will create a connected client to
|
|
20
|
+
this will create a connected client to Redis using the default settings:
|
|
21
21
|
|
|
22
22
|
```javascript
|
|
23
23
|
'use strict';
|
|
@@ -29,14 +29,14 @@ const Table = setUpTable();
|
|
|
29
29
|
module.exports = Table;
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
You can also pass your own configuration options to the
|
|
32
|
+
You can also pass your own configuration options to the Redis client. See the
|
|
33
33
|
redis [client configuration guide](https://github.com/redis/node-redis/blob/master/docs/client-configuration.md)
|
|
34
34
|
for available options:
|
|
35
35
|
|
|
36
36
|
```javascript
|
|
37
37
|
'use strict';
|
|
38
38
|
|
|
39
|
-
const {setUpTable} = require('model-redis')
|
|
39
|
+
const {setUpTable} = require('model-redis');
|
|
40
40
|
|
|
41
41
|
const conf = {
|
|
42
42
|
socket: {
|
|
@@ -45,7 +45,7 @@ const conf = {
|
|
|
45
45
|
},
|
|
46
46
|
username: admin,
|
|
47
47
|
password: hunter42
|
|
48
|
-
}
|
|
48
|
+
};
|
|
49
49
|
|
|
50
50
|
const Table = setUpTable({redisConf: conf});
|
|
51
51
|
|
|
@@ -53,12 +53,12 @@ module.exports = Table;
|
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
It can also take a Redis client object, if you would like to have more control
|
|
56
|
-
or use a custom version on
|
|
56
|
+
or use a custom version on Redis.
|
|
57
57
|
|
|
58
58
|
```javascript
|
|
59
59
|
'use strict';
|
|
60
60
|
|
|
61
|
-
const {setUpTable} = require('model-redis')
|
|
61
|
+
const {setUpTable} = require('model-redis');
|
|
62
62
|
|
|
63
63
|
const {createClient} = require('redis');
|
|
64
64
|
const client = createClient();
|
|
@@ -70,6 +70,23 @@ module.exports = Table;
|
|
|
70
70
|
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
### Prefix key
|
|
74
|
+
|
|
75
|
+
At some point, the Redis package removed the option to prefix a string to the
|
|
76
|
+
keys. This functionally has been added back with this package
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
'use strict';
|
|
80
|
+
|
|
81
|
+
const {setUpTable} = require('model-redis');
|
|
82
|
+
|
|
83
|
+
const Table = setUpTable({
|
|
84
|
+
prefix: 'auth_app'
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
module.exports = Table;
|
|
88
|
+
```
|
|
89
|
+
|
|
73
90
|
Once we have have our table object, we can start building using the ORM!
|
|
74
91
|
|
|
75
92
|
## ORM API
|