Simple in-memory cache (run as server or embedding Go-library)
MIT License
From source:
go get -u github.com/msoap/raphanus
# build server & cli
cd $GOPATH/src/github.com/msoap/raphanus/server && go build -o $GOPATH/bin/raphanus-server
# cli client not implement now
cd $GOPATH/src/github.com/msoap/raphanus/cli && go build -o $GOPATH/bin/raphanus-cli
From Docker hub:
docker pull msoap/raphanus
raphanus-server [options]
options:
-address string
address for bind server (default "localhost:8771")
-auth string
user:password for enable HTTP basic authentication
-filename string
file name for storage on disk, '' - for work in-memory only
-sync-time int
time in seconds between sync on disk
-version
get version
in Docker container:
docker run --name raphanus --publish 8771:8771 --detach msoap/raphanus
curl -s 'http://localhost:8771/v1/length'
curl -s 'http://localhost:8771/v1/keys'
curl -s -u user:pass 'http://localhost:8771/v1/stat'
k1
with ttl (100 sec): curl -s -X POST -d 123 'http://localhost:8771/v1/int/k1?ttl=100'
k1
: curl -s 'http://localhost:8771/v1/int/k1'
k2
without ttl: curl -s -X POST -d 'str value' 'http://localhost:8771/v1/str/k2'
k2
: curl -s 'http://localhost:8771/v1/str/k2'
curl -s -X POST -H 'Content-Type: application/json' -d '["v1", "v2"]' http://localhost:8771/v1/list/k3
curl -s 'http://localhost:8771/v1/list/k3'
curl -s -X POST -H 'Content-Type: application/json' -d '{"dk1": "v1", "dk2": "v2"}' http://localhost:8771/v1/dict/k4
curl -s 'http://localhost:8771/v1/dict/k4'
k1
: curl -s -X DELETE http://localhost:8771/v1/remove/k1
import (
"github.com/msoap/raphanus"
"github.com/msoap/raphanus/common"
)
func main() {
raph := raphanus.New()
// or with storage, with sync every 300 seconds
// raph := raphanus.New().SetStorage("filename.db", 300)
raph.SetStr("key", "value")
v, err := raph.GetStr("key")
if err == raphanuscommon.ErrKeyNotExists {
...
}
raph.UnderLock(func () {
v, err := raph.GetStr("k1")
if err != nil {
return
}
raph.SetStr("k1", v + " updated", 0)
})
}
import (
"github.com/msoap/raphanus/client"
"github.com/msoap/raphanus/common"
)
func main() {
// with default address:
raph := raphanusclient.New()
// or with another address:
// raph := raphanusclient.New(raphanusclient.Cfg{Address: "http://localhost:8771"})
// or with authentication:
// raph := raphanusclient.New(raphanusclient.Cfg{User: "uname", Password: "pass"})
raph.SetStr("key", "value", 3600)
v, err := raph.GetStr("key")
if err == raphanuscommon.ErrKeyNotExists {
...
}
}
An example of using the library: simple.go
$ docker run --name raphanus --publish 8771:8771 --rm msoap/raphanus
$ docker run --name redis --rm --publish 6379:6379 redis
$ docker run --name memcache --rm --publish 11211:11211 memcached
$ make run-benchmark
Benchmark_raphanusServer-4 5000 1196515 ns/op 9432 B/op 128 allocs/op
Benchmark_raphanusEmbed-4 5000000 1633 ns/op 184 B/op 4 allocs/op
Benchmark_redis-4 10000 636079 ns/op 343 B/op 19 allocs/op
Benchmark_memcache-4 10000 689439 ns/op 2744 B/op 63 allocs/op
Benchmark_raphanusServerTTL-4 5000 1178499 ns/op 9459 B/op 130 allocs/op
Benchmark_raphanusEmbedTTL-4 5000000 2554 ns/op 194 B/op 6 allocs/op
Benchmark_redisTTL-4 10000 791056 ns/op 417 B/op 21 allocs/op
Benchmark_memcacheTTL-4 10000 733611 ns/op 2744 B/op 63 allocs/op
Redis 3.2.7
memcached 1.4.34
$ make run-benchmark
Benchmark_raphanusServer-4 20000 349394 ns/op 9465 B/op 131 allocs/op
Benchmark_raphanusEmbed-4 3000000 1919 ns/op 213 B/op 7 allocs/op
Benchmark_boltdb-4 30000 258030 ns/op 34320 B/op 69 allocs/op
Benchmark_redis-4 50000 128278 ns/op 411 B/op 23 allocs/op
Benchmark_memcache-4 50000 135533 ns/op 2752 B/op 63 allocs/op
Benchmark_raphanusServerTTL-4 20000 356989 ns/op 9499 B/op 133 allocs/op
Benchmark_raphanusEmbedTTL-4 2000000 3347 ns/op 244 B/op 9 allocs/op
Benchmark_redisTTL-4 50000 127851 ns/op 473 B/op 25 allocs/op
Benchmark_memcacheTTL-4 50000 135326 ns/op 2811 B/op 67 allocs/op