1 Star 0 Fork 0

荒野無燈 / msgpstore

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

jsonstore :convenience_store:

GoDoc

MsgpStore is a Go-library for a simple thread-safe in-memory JSON key-store with persistent backend. It's made for those times where you don't need a RDBMS like MySQL, or a NoSQL like MongoDB - basically when you just need a simple keystore. A really simple keystore. MsgpStore is used in those times you don't need a distributed keystore like etcd, or a remote keystore Redis or a local keystore like Bolt. Its really for those times where you just need a key-value store file. only string data type supported.

Usage

First, install the library using:

go get -u -v bitbucket.org/8ox86/msgpstore

Then you can add it to your program. Check out the examples, or see below for basic usage:

ks := new(jsonstore.MsgpStore)

err := ks.Set("human:1", "this is human 1")
if err != nil {
  panic(err)
}

// Saving will automatically gzip if .gz is provided
if err = msgpstore.Save(ks, "humans.json.gz"); err != nil {
  panic(err)
}

// Load any JSON / GZipped JSON
ks2, err := msgpstore.Open("humans.json.gz")
if err != nil {
  panic(err)
}

// get the data back via an interface
var human string
err = ks2.Get("human:1", &human)
if err != nil {
  panic(err)
}
fmt.Println(human) // Prints 'this is human 1'

Dev

Benchmark against using Redis and BoltDB as KeyStores using Go1.10 (Intel i7-8700K CPU @ 4.50GHz). Take away is that setting/getting is faster in MsgpStore (because its just a map), but opening is much slower (because its a file that is read into memory). So don't use this if you have to store 1,000,000+ things!

BenchmarkOpen100-12                30000             43435 ns/op
BenchmarkOpen10000-12                300           4701279 ns/op
BenchmarkGet-12                 30000000                41.0 ns/op
BenchmarkSet-12                  3000000               382 ns/op
BenchmarkSave100-12                 5000            400946 ns/op
BenchmarkSave10000-12                 50          36788082 ns/op
BenchmarkSaveGz100-12              10000            241150 ns/op
BenchmarkSaveGz10000-12              100          17769683 ns/op
PASS
ok      bitbucket.org/8ox86/msgpstore   14.531s
BenchmarkOpen100-12        	   20000	     81664 ns/op
BenchmarkOpen10000-12      	     200	   9016223 ns/op
BenchmarkGet-12            	 2000000	       807 ns/op
BenchmarkSet-12            	 1000000	      1038 ns/op
BenchmarkSave100-12        	   20000	     97446 ns/op
BenchmarkSave10000-12      	     200	  31401238 ns/op
BenchmarkSaveGz100-12      	    5000	    250647 ns/op
BenchmarkSaveGz10000-12    	     100	  26312147 ns/op
PASS
ok  	_/home/hacklog/repo/jsonstore	22.814s
▶  cat bolt.txt
goos: linux
goarch: amd64
BenchmarkSet-12                     2000           1140323 ns/op
BenchmarkGet-12                  1000000              1300 ns/op
BenchmarkOpen100-12               200000             10652 ns/op
BenchmarkOpen10000-12             200000              9888 ns/op
PASS
ok      command-line-arguments  8.545s
$ go test -bench=. tests/redis/* > redis.txt
$ go test -bench=. tests/bolt/* > bolt.txt
$ go test -bench=. > msgpstore.txt
$ benchcmp bolt.txt msgpstore.txt
$ benchcmp redis.txt msgpstore.txt

License

MIT

MIT License Copyright (c) 2017 Zack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

MsgpStore is a Go-library for a simple thread-safe in-memory JSON key-store with persistent backend. It's made for those times where you don't need a RDBMS like MySQL, or a NoSQL like MongoDB - basically when you just need a simple keystore. A really simple keystore. MsgpStore is used in those times you don't need a distributed keystore like etc... 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/8ox86/msgpstore.git
git@gitee.com:8ox86/msgpstore.git
8ox86
msgpstore
msgpstore
master

搜索帮助