-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
4,696 additions
and
37,878 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,111 +9,81 @@ Providing a standard *Store Interface* and **Redis**-like API that you can use i | |
|
||
Loading via script tag: | ||
|
||
<script style="text/javascript" src="/path/to/script/min.js"> | ||
```html | ||
<script style="text/javascript" src="/path/to/script/min.js"> | ||
``` | ||
With [node](http://nodejs.org) previously installed: | ||
$ npm install min | ||
|
||
If you are using [component](http://component.io), you can install it with: | ||
|
||
$ component install iwillwen/mindb | ||
```shell | ||
$ npm install min | ||
``` | ||
# Basic Usage | ||
Common key-value via such as `SET`, `GET`, etc. | ||
min.set('foo', 'bar', function(err) { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
min.get('foo', function(err, value) { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
console.log(value); //=> bar | ||
}); | ||
}); | ||
```javascript | ||
min.set('foo', 'bar') | ||
.then(() => min.get('foo')) | ||
.then(value => console.log(value)) //=> bar | ||
.catch(err => console.error(err)) | ||
``` | ||
## Basic commands | ||
- `set` Set the value of a key `(key, value[, callback])` | ||
- `setnx` Set the value of a key, only if the key does not exist `(key, value[, callback])` | ||
- `setex` Set the value and expiration of a key `(key, seconds, value[, callback])` | ||
- `psetex` Set the value and expiration in milliseconds of a key `(key, millseconds, value[, callback])` | ||
- `mset` Set multiple keys to multiple values `(plainObject[, callback])` | ||
- `msetnx` Set multiple keys to multiple values, only if none of the keys exist `(plainObject[, callback])` | ||
- `append` Append a value to a key `(key, value[, callback])` | ||
- `get` Get the value of a key `(key[, callback])` | ||
- `mget` Get the values of a set of keys `(keys[, callback])` | ||
- `getset` Set the value of a key and return its old value `(key, value[, callback])` | ||
- `strlen` Get the length of a key `(key[, callback])` | ||
- `incr` Increment the integer value of a key by one `(key[, callback])` | ||
- `incrby` Increment the integer value of a key by the given amount `(key, increment[, callback])` | ||
- `incrbyfloat` Increment the float value of a key by the given amount `(key, increment[, callback])` | ||
- `set` Set the value of a key `(key, value)` | ||
- `setnx` Set the value of a key, only if the key does not exist `(key, value)` | ||
- `setex` Set the value and expiration of a key `(key, seconds, value)` | ||
- `psetex` Set the value and expiration in milliseconds of a key `(key, millseconds, value)` | ||
- `mset` Set multiple keys to multiple values `(plainObject)` | ||
- `msetnx` Set multiple keys to multiple values, only if none of the keys exist `(plainObject)` | ||
- `append` Append a value to a key `(key, value)` | ||
- `get` Get the value of a key `(key)` | ||
- `mget` Get the values of a set of keys `(keys)` | ||
- `getset` Set the value of a key and return its old value `(key, value)` | ||
- `strlen` Get the length of a key `(key)` | ||
- `incr` Increment the integer value of a key by one `(key)` | ||
- `incrby` Increment the integer value of a key by the given amount `(key, increment)` | ||
- `incrbyfloat` Increment the float value of a key by the given amount `(key, increment)` | ||
## Hash, List, Set, Sorted Set | ||
Maybe you can get the way by browsing [Redis Commands](http://redis.io/commands). XD | ||
## Sweet | ||
Nested Callbacks? Maybe you would prefer [Promise](http://promises-aplus.github.io/promises-spec/): | ||
|
||
min.incr('user_id') | ||
.then(function(curr) { | ||
return min.hmset('user-' + curr, { | ||
name: 'Will Wen Gunn', | ||
id: 'iwillwen', | ||
email: '[email protected]' | ||
}); | ||
}) | ||
.then(function(key) { | ||
var id = key.substr(5); | ||
return min.sadd('user-msg-' + id, 'WelCome!'); | ||
}) | ||
.then(function(length) { | ||
// ... | ||
}) | ||
.catch(function(err) { | ||
console.log(err); | ||
}); | ||
|
||
Anymore else? How about `MULTI`? | ||
min.multi() | ||
.incr('msg-seq') | ||
.incr('msg-seq') | ||
.incr('msg-seq') | ||
.exec(function(err, results) { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
console.log(results); //=> [ [ 1 ], [ 2 ], [ 3 ] ] | ||
}); | ||
```javascript | ||
min.multi() | ||
.incr('msg-seq') | ||
.incr('msg-seq') | ||
.incr('msg-seq') | ||
.exec() | ||
.then(results => console.log(results)) //=> [ [ 1 ], [ 2 ], [ 3 ] ] | ||
.catch(err => console.error(err)) | ||
``` | ||
SWEET! Let's run to **Harmony**(ES2015)! | ||
async _ => { | ||
var userId = await min.incr('users:id:seq') | ||
await min.hmset(`user:${userId}`, { | ||
name: 'Will Wen Gunn', | ||
sign: 'iwillwen', | ||
homepage: 'http://lifemap.in' | ||
}) | ||
await min.sadd(`user:${userId}:msgs`, 'Welcome') | ||
} | ||
```javascript | ||
async _ => { | ||
var userId = await min.incr('users:id:seq') | ||
await min.hmset(`user:${userId}`, { | ||
name: 'Will Wen Gunn', | ||
sign: 'iwillwen', | ||
homepage: 'http://lifemap.in' | ||
}) | ||
await min.sadd(`user:${userId}:msgs`, 'Welcome') | ||
} | ||
``` | ||
Support multiple databases: | ||
var Min = min.fork(); | ||
Min.set('foo', 'bar') | ||
.then(/*...*/) | ||
.catch(/*...*/); | ||
|
||
# Store Interface | ||
Read the [Store Interface Documentation](https://github.com/iwillwen/mindb/blob/master/docs/store_interface.md). | ||
```javascript | ||
var Min = min.fork() | ||
Min.set('foo', 'bar') | ||
.then(/*...*/) | ||
.catch(/*...*/) | ||
``` | ||
# Contributing | ||
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 | |
Hint: | ||
$ git flow feature start [featurename] | ||
$ git add . | ||
$ git commit -m 'new feature description' | ||
$ git flow feature finish [featurename] | ||
```shell | ||
$ git flow feature start [featurename] | ||
$ git add . | ||
$ git commit -m 'new feature description' | ||
$ git flow feature finish [featurename] | ||
``` | ||
# License | ||
Copyright (c) 2012-2013 Will Wen Gunn([email protected]) | ||
Copyright (c) 2012-2019 Will Wen Gunn([email protected]) | ||
All rights reserved. | ||
MIT License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,108 +7,81 @@ MinDB 提供一个标准的存储接口(`Store Interface`)和 **Redis** 风格 | |
|
||
普通`script`标签引入: | ||
|
||
<script style="text/javascript" src="/path/to/script/min.js"> | ||
```html | ||
<script style="text/javascript" src="/path/to/script/min.js"> | ||
``` | ||
通过 [Node.js](http://nodejs.org) 和 [npm](http://npmjs.org) 安装: | ||
$ npm install min | ||
```shell | ||
$ npm install min | ||
``` | ||
如果你喜欢 [component](http://component.io),你也可以使用它进行安装: | ||
|
||
$ component install iwillwen/mindb | ||
|
||
# 基本使用方法 | ||
基本的键值存储可以通过`SET`、`GET`等命令操作: | ||
min.set('foo', 'bar', function(err) { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
min.get('foo', function(err, value) { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
console.log(value); //=> bar | ||
}); | ||
}); | ||
```javascript | ||
min.set('foo', 'bar') | ||
.then(() => min.get('foo')) | ||
.then(value => console.log(value)) //=> bar | ||
.catch(err => console.error(err)) | ||
``` | ||
## 基本方法 | ||
- `set` 对指定键设置数据 `(key, value[, callback])` | ||
- `setnx` 当指定键不存在时,对其设置数据 `(key, value[, callback])` | ||
- `setex` 对指定键设置数据,并设置生命周期 `(key, seconds, value[, callback])` | ||
- `psetex` 对指定键设置数据,并设置以毫秒为单位的生命周期 `(key, millseconds, value[, callback])` | ||
- `mset` 批量对指定键设置数据 `(plainObject[, callback])` | ||
- `msetnx` 当一批指定键全部不存在时,批量对其设置数据 `(plainObject[, callback])` | ||
- `append` 在指定键后插入值 `(key, value[, callback])` | ||
- `get` 获取指定键的值 `(key[, callback])` | ||
- `mget` 批量获取指定键的值 `(keys[, callback])` | ||
- `getset` 对指定键设置数据并返回其之前的值 `(key, value[, callback])` | ||
- `strlen` 获取指定键值的长度 `(key[, callback])` | ||
- `incr` 将指定键中储存的数字值增一 `(key[, callback])` | ||
- `incrby` 将指定键中储存的数字值增加若干量 `(key, increment[, callback])` | ||
- `incrbyfloat` 将指定键中储存的浮点值增加若干量 `(key, increment[, callback])` | ||
- `set` 对指定键设置数据 `(key, value)` | ||
- `setnx` 当指定键不存在时,对其设置数据 `(key, value)` | ||
- `setex` 对指定键设置数据,并设置生命周期 `(key, seconds, value)` | ||
- `psetex` 对指定键设置数据,并设置以毫秒为单位的生命周期 `(key, millseconds, value)` | ||
- `mset` 批量对指定键设置数据 `(plainObject)` | ||
- `msetnx` 当一批指定键全部不存在时,批量对其设置数据 `(plainObject)` | ||
- `append` 在指定键后插入值 `(key, value)` | ||
- `get` 获取指定键的值 `(key)` | ||
- `mget` 批量获取指定键的值 `(keys)` | ||
- `getset` 对指定键设置数据并返回其之前的值 `(key, value)` | ||
- `strlen` 获取指定键值的长度 `(key)` | ||
- `incr` 将指定键中储存的数字值增一 `(key)` | ||
- `incrby` 将指定键中储存的数字值增加若干量 `(key, increment)` | ||
- `incrbyfloat` 将指定键中储存的浮点值增加若干量 `(key, increment)` | ||
## Hash, List, Set, Sorted Set | ||
你或许可以在 [Redis](http://redis.io/commands) 的官方网站中得到启示。 | ||
## 语法糖([Syntactic sugar](http://zh.wikipedia.org/zh/%E8%AF%AD%E6%B3%95%E7%B3%96)) | ||
不喜欢嵌套回调?你或许会喜欢 [Promise](http://promises-aplus.github.io/promises-spec/): | ||
|
||
min.incr('user_id') | ||
.then(function(curr) { | ||
return min.hmset('user-' + curr, { | ||
name: 'Will Wen Gunn', | ||
id: 'iwillwen', | ||
email: '[email protected]' | ||
}); | ||
}) | ||
.then(function(key) { | ||
var id = key.substr(5); | ||
return min.sadd('user-msg-' + id, 'WelCome!'); | ||
}) | ||
.then(function(length) { | ||
// ... | ||
}) | ||
.catch(function(err) { | ||
console.log(err); | ||
}); | ||
|
||
还不行?不需要依赖?那么来看看`MULTI`吧: | ||
min.multi() | ||
.incr('msg-seq') | ||
.incr('msg-seq') | ||
.incr('msg-seq') | ||
.exec(function(err, results) { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
console.log(results); //=> [ [ 1 ], [ 2 ], [ 3 ] ] | ||
}); | ||
```javascript | ||
min.multi() | ||
.incr('msg-seq') | ||
.incr('msg-seq') | ||
.incr('msg-seq') | ||
.exec() | ||
.then(results => console.log(results)) //=> [ [ 1 ], [ 2 ], [ 3 ] ] | ||
.catch(err => console.error(err)) | ||
``` | ||
ES2015的时代已经到来,你还在等什么? | ||
async _ => { | ||
var userId = await min.incr('users:id:seq') | ||
await min.hmset(`user:${userId}`, { | ||
name: 'Will Wen Gunn', | ||
sign: 'iwillwen', | ||
homepage: 'http://lifemap.in' | ||
}) | ||
await min.sadd(`user:${userId}:msgs`, 'Welcome') | ||
} | ||
```javascript | ||
async _ => { | ||
var userId = await min.incr('users:id:seq') | ||
await min.hmset(`user:${userId}`, { | ||
name: 'Will Wen Gunn', | ||
sign: 'iwillwen', | ||
homepage: 'http://lifemap.in' | ||
}) | ||
await min.sadd(`user:${userId}:msgs`, 'Welcome') | ||
} | ||
``` | ||
MinDB 也支持多数据库: | ||
var Min = min.fork(); | ||
Min.set('foo', 'bar') | ||
.then(/*...*/) | ||
.catch(/*...*/); | ||
```javascript | ||
var Min = min.fork() | ||
Min.set('foo', 'bar') | ||
.then(/*...*/) | ||
.catch(/*...*/) | ||
``` | ||
# Store Interface | ||
请阅读 [Store Interface 文档](https://github.com/iwillwen/mindb/blob/master/docs/store_interface.md). | ||
|
@@ -129,10 +102,12 @@ MinDB 也支持多数据库: | |
提示: | ||
$ git flow feature start [featurename] | ||
$ git add . | ||
$ git commit -m 'new feature description' | ||
$ git flow feature finish [featurename] | ||
```shell | ||
$ git flow feature start [featurename] | ||
$ git add . | ||
$ git commit -m 'new feature description' | ||
$ git flow feature finish [featurename] | ||
``` | ||
# 许可 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ exports.banner = | |
"Will Wen Gunn(iwillwen) and other contributors\n\n" + | ||
|
||
"@license MIT-license\n" + | ||
"@copyright 2012-2015 iwillwen([email protected])" | ||
"@copyright 2012-2018 iwillwen([email protected])" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.