https://github.com/hqbobo/dcache
distribute cache base on redis
https://github.com/hqbobo/dcache
distributed-storage golang redis
Last synced: 6 months ago
JSON representation
distribute cache base on redis
- Host: GitHub
- URL: https://github.com/hqbobo/dcache
- Owner: hqbobo
- Created: 2019-05-22T08:02:00.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-27T08:20:12.000Z (about 7 years ago)
- Last Synced: 2024-06-21T20:06:57.370Z (about 2 years ago)
- Topics: distributed-storage, golang, redis
- Language: Go
- Homepage:
- Size: 2.35 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dcache
## Description
>distribute cache implement with redis. local memory is also used which can speed up get operation.
main function as below
1. support redis and redis cluster mode
2. support local cache. all set operation will remian a copy of data in memory(with timeout).
3. All dcache client will get a copy of data after set opertion and save in their own memory(with timeout).
4. All data has been marshelled into json, feel free to store struct stuff
5. Set your own logger and TextSerialize
##Detail
> Option
```$xslt
type Options struct {
Ip string //redis server ip
Port int //redis server port
Pass string //redis server password
Db int //redis server db
PoolSize int //redis server clientpool size
ClusterMode bool //redis server running cluster mode?
Serialize TextSerialize //interface used to marshal object into text
Logger Logger //interface used for log
}
```
> TextSerialize
you can design your own TextSerialize if speed is concerned
```$xslt
type TextSerialize interface {
Marshal(o interface{}) (string, error)
Unmarshal(data []byte, v interface{}) error
}
```
> Logger
fit to the log system that you are familiar with
```$xslt
type Logger interface {
Debug(v ...interface{})
Info(v ...interface{})
Notice(v ...interface{})
Warn(v ...interface{})
Error(v ...interface{})
Panic(v ...interface{})
}
```
## Example
> [Source Code](https://github.com/hqbobo/dcache/example) see in the example directory
```
package main
import (
"github.com/hqbobo/dcache"
)
func main() {
dcache.Init(dcache.Options{
Ip: "127.0.0.1",
Port: 6379,
Pass: "",
Db: 1,
PoolSize: 10,
ClusterMode: false,
})
var val string
dcache.GetCache().Get("aaaa", &val)
dcache.GetCache().Set("aaaa", "bbbb", 100)
dcache.GetCache().Get("aaaa", &val)
select {}
}
```