Skip to content

Commit c6a60d3

Browse files
committed
Rewrite with TypeScript
1 parent 4fd150f commit c6a60d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4696
-37878
lines changed

README.md

Lines changed: 59 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -9,111 +9,81 @@ Providing a standard *Store Interface* and **Redis**-like API that you can use i
99

1010
Loading via script tag:
1111

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+
```
1315
1416
With [node](http://nodejs.org) previously installed:
1517
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+
```
2121
2222
# Basic Usage
2323
2424
Common key-value via such as `SET`, `GET`, etc.
2525
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+
```
3932
4033
## 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)`
5548
5649
## Hash, List, Set, Sorted Set
5750
Maybe you can get the way by browsing [Redis Commands](http://redis.io/commands). XD
5851
5952
## 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-
8253
Anymore else? How about `MULTI`?
8354
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+
```
9564
9665
SWEET! Let's run to **Harmony**(ES2015)!
9766
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+
```
10778
10879
Support multiple databases:
10980
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+
```
11787
11888
# Contributing
11989
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
132102
133103
Hint:
134104
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+
```
139111
140112
# License
141113
142-
Copyright (c) 2012-2013 Will Wen Gunn([email protected])
114+
Copyright (c) 2012-2019 Will Wen Gunn([email protected])
143115
All rights reserved.
144116
145117
MIT License

README_zhcn.md

Lines changed: 58 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -7,108 +7,81 @@ MinDB 提供一个标准的存储接口(`Store Interface`)和 **Redis** 风格
77

88
普通`script`标签引入:
99

10-
<script style="text/javascript" src="/path/to/script/min.js">
10+
```html
11+
<script style="text/javascript" src="/path/to/script/min.js">
12+
```
1113
1214
通过 [Node.js](http://nodejs.org) 和 [npm](http://npmjs.org) 安装:
1315
14-
$ npm install min
16+
```shell
17+
$ npm install min
18+
```
1519
16-
如果你喜欢 [component](http://component.io),你也可以使用它进行安装:
17-
18-
$ component install iwillwen/mindb
19-
2020
# 基本使用方法
2121
2222
基本的键值存储可以通过`SET``GET`等命令操作:
2323
24-
min.set('foo', 'bar', function(err) {
25-
if (err) {
26-
return console.error(err);
27-
}
28-
29-
min.get('foo', function(err, value) {
30-
if (err) {
31-
return console.error(err);
32-
}
33-
34-
console.log(value); //=> bar
35-
});
36-
});
24+
```javascript
25+
min.set('foo', 'bar')
26+
.then(() => min.get('foo'))
27+
.then(value => console.log(value)) //=> bar
28+
.catch(err => console.error(err))
29+
```
3730
3831
## 基本方法
39-
- `set` 对指定键设置数据 `(key, value[, callback])`
40-
- `setnx` 当指定键不存在时,对其设置数据 `(key, value[, callback])`
41-
- `setex` 对指定键设置数据,并设置生命周期 `(key, seconds, value[, callback])`
42-
- `psetex` 对指定键设置数据,并设置以毫秒为单位的生命周期 `(key, millseconds, value[, callback])`
43-
- `mset` 批量对指定键设置数据 `(plainObject[, callback])`
44-
- `msetnx` 当一批指定键全部不存在时,批量对其设置数据 `(plainObject[, callback])`
45-
- `append` 在指定键后插入值 `(key, value[, callback])`
46-
- `get` 获取指定键的值 `(key[, callback])`
47-
- `mget` 批量获取指定键的值 `(keys[, callback])`
48-
- `getset` 对指定键设置数据并返回其之前的值 `(key, value[, callback])`
49-
- `strlen` 获取指定键值的长度 `(key[, callback])`
50-
- `incr` 将指定键中储存的数字值增一 `(key[, callback])`
51-
- `incrby` 将指定键中储存的数字值增加若干量 `(key, increment[, callback])`
52-
- `incrbyfloat` 将指定键中储存的浮点值增加若干量 `(key, increment[, callback])`
32+
- `set` 对指定键设置数据 `(key, value)`
33+
- `setnx` 当指定键不存在时,对其设置数据 `(key, value)`
34+
- `setex` 对指定键设置数据,并设置生命周期 `(key, seconds, value)`
35+
- `psetex` 对指定键设置数据,并设置以毫秒为单位的生命周期 `(key, millseconds, value)`
36+
- `mset` 批量对指定键设置数据 `(plainObject)`
37+
- `msetnx` 当一批指定键全部不存在时,批量对其设置数据 `(plainObject)`
38+
- `append` 在指定键后插入值 `(key, value)`
39+
- `get` 获取指定键的值 `(key)`
40+
- `mget` 批量获取指定键的值 `(keys)`
41+
- `getset` 对指定键设置数据并返回其之前的值 `(key, value)`
42+
- `strlen` 获取指定键值的长度 `(key)`
43+
- `incr` 将指定键中储存的数字值增一 `(key)`
44+
- `incrby` 将指定键中储存的数字值增加若干量 `(key, increment)`
45+
- `incrbyfloat` 将指定键中储存的浮点值增加若干量 `(key, increment)`
5346
5447
## Hash, List, Set, Sorted Set
5548
你或许可以在 [Redis](http://redis.io/commands) 的官方网站中得到启示。
5649
5750
## 语法糖([Syntactic sugar](http://zh.wikipedia.org/zh/%E8%AF%AD%E6%B3%95%E7%B3%96))
58-
不喜欢嵌套回调?你或许会喜欢 [Promise](http://promises-aplus.github.io/promises-spec/):
59-
60-
min.incr('user_id')
61-
.then(function(curr) {
62-
return min.hmset('user-' + curr, {
63-
name: 'Will Wen Gunn',
64-
id: 'iwillwen',
65-
66-
});
67-
})
68-
.then(function(key) {
69-
var id = key.substr(5);
70-
71-
return min.sadd('user-msg-' + id, 'WelCome!');
72-
})
73-
.then(function(length) {
74-
// ...
75-
})
76-
.catch(function(err) {
77-
console.log(err);
78-
});
79-
8051
还不行?不需要依赖?那么来看看`MULTI`吧:
8152
82-
min.multi()
83-
.incr('msg-seq')
84-
.incr('msg-seq')
85-
.incr('msg-seq')
86-
.exec(function(err, results) {
87-
if (err) {
88-
return console.error(err);
89-
}
90-
91-
console.log(results); //=> [ [ 1 ], [ 2 ], [ 3 ] ]
92-
});
53+
```javascript
54+
min.multi()
55+
.incr('msg-seq')
56+
.incr('msg-seq')
57+
.incr('msg-seq')
58+
.exec()
59+
.then(results => console.log(results)) //=> [ [ 1 ], [ 2 ], [ 3 ] ]
60+
.catch(err => console.error(err))
61+
```
9362
9463
ES2015的时代已经到来,你还在等什么?
9564
96-
async _ => {
97-
var userId = await min.incr('users:id:seq')
98-
await min.hmset(`user:${userId}`, {
99-
name: 'Will Wen Gunn',
100-
sign: 'iwillwen',
101-
homepage: 'http://lifemap.in'
102-
})
103-
await min.sadd(`user:${userId}:msgs`, 'Welcome')
104-
}
65+
```javascript
66+
async _ => {
67+
var userId = await min.incr('users:id:seq')
68+
await min.hmset(`user:${userId}`, {
69+
name: 'Will Wen Gunn',
70+
sign: 'iwillwen',
71+
homepage: 'http://lifemap.in'
72+
})
73+
await min.sadd(`user:${userId}:msgs`, 'Welcome')
74+
}
75+
```
10576
10677
MinDB 也支持多数据库:
10778
108-
var Min = min.fork();
109-
Min.set('foo', 'bar')
110-
.then(/*...*/)
111-
.catch(/*...*/);
79+
```javascript
80+
var Min = min.fork()
81+
Min.set('foo', 'bar')
82+
.then(/*...*/)
83+
.catch(/*...*/)
84+
```
11285
11386
# Store Interface
11487
请阅读 [Store Interface 文档](https://github.com/iwillwen/mindb/blob/master/docs/store_interface.md).
@@ -129,10 +102,12 @@ MinDB 也支持多数据库:
129102
130103
提示:
131104
132-
$ git flow feature start [featurename]
133-
$ git add .
134-
$ git commit -m 'new feature description'
135-
$ 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+
```
136111
137112
# 许可
138113

build/banner.js renamed to assets/banner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ exports.banner =
88
"Will Wen Gunn(iwillwen) and other contributors\n\n" +
99

1010
"@license MIT-license\n" +
11-
"@copyright 2012-2015 iwillwen([email protected])"
11+
"@copyright 2012-2018 iwillwen([email protected])"

assets/mindb.png

15.8 KB
Loading

0 commit comments

Comments
 (0)