@@ -9,111 +9,81 @@ Providing a standard *Store Interface* and **Redis**-like API that you can use i
9
9
10
10
Loading via script tag:
11
11
12
- <script style="text/javascript" src="/path/to/script/min.js">
12
+ ``` html
13
+ <script style =" text /javascript " src =" /path/to/script/min.js" >
14
+ ` ` `
13
15
14
16
With [node](http://nodejs.org) previously installed:
15
17
16
- $ npm install min
17
-
18
- If you are using [ component] ( http://component.io ) , you can install it with:
19
-
20
- $ component install iwillwen/mindb
18
+ ` ` ` shell
19
+ $ npm install min
20
+ ` ` `
21
21
22
22
# Basic Usage
23
23
24
24
Common key-value via such as ` SET ` , ` GET ` , etc.
25
25
26
- min.set('foo', 'bar', function(err) {
27
- if (err) {
28
- return console.error(err);
29
- }
30
-
31
- min.get('foo', function(err, value) {
32
- if (err) {
33
- return console.error(err);
34
- }
35
-
36
- console.log(value); //=> bar
37
- });
38
- });
26
+ ` ` ` javascript
27
+ min .set (' foo' , ' bar' )
28
+ .then (() => min .get (' foo' ))
29
+ .then (value => console .log (value)) // => bar
30
+ .catch (err => console .error (err))
31
+ ` ` `
39
32
40
33
## Basic commands
41
- - ` set ` Set the value of a key ` (key, value[, callback] ) `
42
- - ` setnx ` Set the value of a key, only if the key does not exist ` (key, value[, callback] ) `
43
- - ` setex ` Set the value and expiration of a key ` (key, seconds, value[, callback] ) `
44
- - ` psetex ` Set the value and expiration in milliseconds of a key ` (key, millseconds, value[, callback] ) `
45
- - ` mset ` Set multiple keys to multiple values ` (plainObject[, callback] ) `
46
- - ` msetnx ` Set multiple keys to multiple values, only if none of the keys exist ` (plainObject[, callback] ) `
47
- - ` append ` Append a value to a key ` (key, value[, callback] ) `
48
- - ` get ` Get the value of a key ` (key[, callback] ) `
49
- - ` mget ` Get the values of a set of keys ` (keys[, callback] ) `
50
- - ` getset ` Set the value of a key and return its old value ` (key, value[, callback] ) `
51
- - ` strlen ` Get the length of a key ` (key[, callback] ) `
52
- - ` incr ` Increment the integer value of a key by one ` (key[, callback] ) `
53
- - ` incrby ` Increment the integer value of a key by the given amount ` (key, increment[, callback] ) `
54
- - ` incrbyfloat ` Increment the float value of a key by the given amount ` (key, increment[, callback] ) `
34
+ - ` set` Set the value of a key ` (key, value)`
35
+ - ` setnx` Set the value of a key, only if the key does not exist ` (key, value)`
36
+ - ` setex` Set the value and expiration of a key ` (key, seconds, value)`
37
+ - ` psetex` Set the value and expiration in milliseconds of a key ` (key, millseconds, value)`
38
+ - ` mset` Set multiple keys to multiple values ` (plainObject)`
39
+ - ` msetnx` Set multiple keys to multiple values, only if none of the keys exist ` (plainObject)`
40
+ - ` append` Append a value to a key ` (key, value)`
41
+ - ` get` Get the value of a key ` (key)`
42
+ - ` mget` Get the values of a set of keys ` (keys)`
43
+ - ` getset` Set the value of a key and return its old value ` (key, value)`
44
+ - ` strlen` Get the length of a key ` (key)`
45
+ - ` incr` Increment the integer value of a key by one ` (key)`
46
+ - ` incrby` Increment the integer value of a key by the given amount ` (key, increment)`
47
+ - ` incrbyfloat` Increment the float value of a key by the given amount ` (key, increment)`
55
48
56
49
## Hash, List, Set, Sorted Set
57
50
Maybe you can get the way by browsing [Redis Commands](http://redis.io/commands). XD
58
51
59
52
## Sweet
60
- Nested Callbacks? Maybe you would prefer [ Promise] ( http://promises-aplus.github.io/promises-spec/ ) :
61
-
62
- min.incr('user_id')
63
- .then(function(curr) {
64
- return min.hmset('user-' + curr, {
65
- name: 'Will Wen Gunn',
66
- id: 'iwillwen',
67
-
68
- });
69
- })
70
- .then(function(key) {
71
- var id = key.substr(5);
72
-
73
- return min.sadd('user-msg-' + id, 'WelCome!');
74
- })
75
- .then(function(length) {
76
- // ...
77
- })
78
- .catch(function(err) {
79
- console.log(err);
80
- });
81
-
82
53
Anymore else? How about ` MULTI ` ?
83
54
84
- min.multi()
85
- .incr('msg-seq')
86
- .incr('msg-seq')
87
- .incr('msg-seq')
88
- .exec(function(err, results) {
89
- if (err) {
90
- return console.error(err);
91
- }
92
-
93
- console.log(results); //=> [ [ 1 ], [ 2 ], [ 3 ] ]
94
- });
55
+ ` ` ` javascript
56
+ min .multi ()
57
+ .incr (' msg-seq' )
58
+ .incr (' msg-seq' )
59
+ .incr (' msg-seq' )
60
+ .exec ()
61
+ .then (results => console .log (results)) // => [ [ 1 ], [ 2 ], [ 3 ] ]
62
+ .catch (err => console .error (err))
63
+ ` ` `
95
64
96
65
SWEET! Let's run to **Harmony**(ES2015)!
97
66
98
- async _ => {
99
- var userId = await min.incr('users:id:seq')
100
- await min.hmset(`user:${userId}`, {
101
- name: 'Will Wen Gunn',
102
- sign: 'iwillwen',
103
- homepage: 'http://lifemap.in'
104
- })
105
- await min.sadd(`user:${userId}:msgs`, 'Welcome')
106
- }
67
+ ` ` ` javascript
68
+ async _ => {
69
+ var userId = await min .incr (' users:id:seq' )
70
+ await min .hmset (` user:${ userId} ` , {
71
+ name: ' Will Wen Gunn' ,
72
+ sign: ' iwillwen' ,
73
+ homepage: ' http://lifemap.in'
74
+ })
75
+ await min .sadd (` user:${ userId} :msgs` , ' Welcome' )
76
+ }
77
+ ` ` `
107
78
108
79
Support multiple databases:
109
80
110
- var Min = min.fork();
111
- Min.set('foo', 'bar')
112
- .then(/*...*/)
113
- .catch(/*...*/);
114
-
115
- # Store Interface
116
- Read the [ Store Interface Documentation] ( https://github.com/iwillwen/mindb/blob/master/docs/store_interface.md ) .
81
+ ` ` ` javascript
82
+ var Min = min .fork ()
83
+ Min .set (' foo' , ' bar' )
84
+ .then (/* ...*/ )
85
+ .catch (/* ...*/ )
86
+ ` ` `
117
87
118
88
# Contributing
119
89
Contribution is welcome.There are more than one way to contribute, and I will appreciate any way you choose.
@@ -132,14 +102,16 @@ We recommend you to use [`git-flow`](https://github.com/nvie/gitflow) to make a
132
102
133
103
Hint:
134
104
135
- $ git flow feature start [featurename]
136
- $ git add .
137
- $ git commit -m 'new feature description'
138
- $ git flow feature finish [featurename]
105
+ ` ` ` shell
106
+ $ git flow feature start [featurename]
107
+ $ git add .
108
+ $ git commit - m ' new feature description'
109
+ $ git flow feature finish [featurename]
110
+ ` ` `
139
111
140
112
# License
141
113
142
- Copyright (c) 2012-
2013 Will Wen Gunn(
[email protected] )
114
+ Copyright (c) 2012-2019 Will Wen Gunn([email protected] )
143
115
All rights reserved.
144
116
145
117
MIT License
0 commit comments