Skip to content

Commit 67612ca

Browse files
committed
1. 优化了ZAdd方法
2. 实现了其他SortedSet方法
1 parent 963a92b commit 67612ca

File tree

8 files changed

+1188
-477
lines changed

8 files changed

+1188
-477
lines changed

README.md

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# JCache 高可用的多级缓存集成方案库
1+
# JCache - High-Availability Multi-Level Cache Integration Library in Golang [[中文版]](./README_zh.md)
22

33

44
![](https://img.shields.io/github/issues/jerbe/jcache?color=green)
@@ -9,40 +9,42 @@
99
[![](https://img.shields.io/badge/doc-go-blue)](https://pkg.go.dev/github.com/jerbe/jcache@v1.1.9)
1010
![](https://img.shields.io/github/languages/code-size/jerbe/jcache?color=blueviolet)
1111

12-
## 说明
12+
## Introduction
1313

14-
* 该项目为golang库,golang项目引用该库即可使用。`go get github.com/jerbe/jcache/v2`
15-
* 此项目是模拟Redis开发的一个轻量的多级缓存集成方案。
16-
* 可同时运行多种驱动,互不干扰。
17-
* 支持Redis驱动,或自定义驱动,只要实现 `driver.Cache` 即可。
18-
* 内置内存缓存驱动。
19-
* 内存驱动支持分布式,基于`ETCD`的服务发现跟选举策略,会选出其中一台实例当做主节点,其余的为从节点。主节点的每次操作都会使用`gRPC`接口同步到其他从节点上;从节点的写操作会使用`gRPC`请求到主节点上再同步到其他从节点上。以尽量达到高可用和数据的一致性。
14+
* This project is a Golang library that can be used by Golang projects. You can use it by running `go get github.com/jerbe/jcache/v2`.
15+
* This project is a lightweight multi-level cache integration solution inspired by Redis.
16+
* It can run multiple drivers simultaneously without interference.
17+
* Supports the Redis driver or custom drivers, as long as they implement the `driver.Cache` interface.
18+
* Built-in memory cache driver.
19+
* The memory driver supports distribution, based on ETCD service discovery and election strategy. It selects one instance as the master node, and the rest as slave nodes. Every operation on the master node is synchronized to the other slave nodes via a `gRPC` interface, and write operations on slave nodes are first sent to the master node via `gRPC` and then synchronized to the other slave nodes to achieve high availability and data consistency.
2020

2121

22-
## 基本架构
2322

24-
现行阶段优先实现功能,未来可能会根据driver的权重指定优先获取顺序。
25-
当前版本的优先顺序按实例化client时指定的driver顺序。
23+
## Basic Architecture
24+
25+
At the current stage, functionality is prioritized, and in the future, the priority retrieval order may be specified based on the driver's weight. The current version's priority order is determined by the driver order specified when instantiating the client.
2626
```go
27-
// 实例化一个以redis驱动为优先获取,内存驱动为后取的客户端
27+
// Instantiate a client with Redis as the preferred driver and memory driver as the fallback.
2828
client := jcache.NewClient(driver.NewRedis(), driver.NewMemory())
2929

3030

31-
// 实例化一个以内存驱动为优先获取,redis驱动为后取的客户端
31+
// Instantiate a client with memory driver as the preferred driver and Redis as the fallback.
3232
client := jcache.NewClient(driver.NewMemory(), driver.NewRedis())
3333
```
34-
### 基本架构图
34+
### Basic Architecture Diagram
35+
3536
![](./assets/架构图.jpeg)
36-
## 进度
37+
## Progress
3738

38-
- [x] Redis驱动支持
39-
- [x] 本机内存驱动支持
40-
- [x] 单机模式支持
41-
- [x] 分布式模式支持
42-
- [x] 从节点的增量同步
43-
- [ ] 节点的全量同步
4439

45-
## 案例
40+
- [x] Redis driver support
41+
- [x] Native memory driver support
42+
- [x] Standalone mode support
43+
- [x] Distributed mode support
44+
- [x] Incremental synchronization of slave nodes
45+
- [ ] Full synchronization of nodes
46+
47+
## Examples
4648
```shell
4749
go get github.com/jerbe/jcache/v2
4850
```
@@ -56,43 +58,43 @@ import (
5658
)
5759

5860
func main(){
59-
// 实例化一个以内存作为驱动的缓存客户端
61+
// Instantiate a cache client with memory as the driver
6062
client := jcache.NewClient()
6163

62-
// 实例化一个分布式的内存驱动缓存客户端
64+
// Instantiate a distributed memory cache client
6365
cfg := driver.DistributeMemoryConfig{
64-
Port: 10080, // 用于启动grpc服务端口,同机器请设置不同端口
65-
Prefix: "/prefix", //根据自己的业务设置对应前缀
66-
// EtcdCfg 根据自己部署的ETCD服务设置对应配置
66+
Port: 10080, // Port for starting the gRPC server, please set different ports for the same machine
67+
Prefix: "/prefix", // Set the corresponding prefix according to your business needs
68+
// EtcdCfg is set according to the configuration of your deployed ETCD service
6769
EtcdCfg: clientv3.Config{
6870
Endpoints: []string{"127.0.0.1:2379"}
6971
}
7072
}
7173
client := driver.NewDistributeMemory(cfg)
72-
73-
74-
75-
// 支持所有操作的客户端,包括 String,Hash,List
74+
75+
76+
77+
// Client that supports all operations, including String, Hash, List, etc.
7678
client := jcache.NewClient(driver.NewMemory())
7779
client.Set(context.Background(),"hello","world", time.Hour)
7880
client.Get(context.Background(),"hello")
7981
client.MGet(context.Background(),"hello","hi")
8082
...
81-
82-
// 仅支持 String 操作的客户端
83+
84+
// Client that supports only String operations
8385
stringClient := jcache.NewStringClien(driver.NewMemory());
8486
stringClient.Set(context.Background(),"hello","world", time.Hour)
8587
stringClient.Get(context.Background(),"hello")
8688
stringClient.MGet(context.Background(),"hello","hi")
8789
...
88-
89-
// 仅支持 Hash 操作的客户端
90+
91+
// Client that supports only Hash operations
9092
hashClient := jcache.NewHashClient(driver.NewMemory());
9193
hashClient.HSet(context.Background(),"hello","world","boom")
9294
hashClient.HGet(context.Background(),"hello","world")
9395
...
94-
95-
// 仅支持 List 操作的客户端
96+
97+
// Client that supports only List operations
9698
listClient := jcache.NewListClient(driver.NewMemory());
9799
listClient.Push(context.Background(),"hello","world")
98100
listClient.Pop(context.Background(),"hello")

README_zh.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# JCache - Golang实现的高可用的多级缓存集成方案库
2+
3+
4+
![](https://img.shields.io/github/issues/jerbe/jcache?color=green)
5+
![](https://img.shields.io/github/stars/jerbe/jcache?color=yellow)
6+
![](https://img.shields.io/github/forks/jerbe/jcache?color=orange)
7+
![](https://img.shields.io/github/license/jerbe/jcache?color=ff69b4)
8+
![](https://img.shields.io/badge/language-go-blue)
9+
[![](https://img.shields.io/badge/doc-go-blue)](https://pkg.go.dev/github.com/jerbe/jcache@v1.1.9)
10+
![](https://img.shields.io/github/languages/code-size/jerbe/jcache?color=blueviolet)
11+
12+
## 说明
13+
14+
* 该项目为golang库,golang项目引用该库即可使用。`go get github.com/jerbe/jcache/v2`
15+
* 此项目是模拟Redis开发的一个轻量的多级缓存集成方案。
16+
* 可同时运行多种驱动,互不干扰。
17+
* 支持Redis驱动,或自定义驱动,只要实现 `driver.Cache` 即可。
18+
* 内置内存缓存驱动。
19+
* 内存驱动支持分布式,基于`ETCD`的服务发现跟选举策略,会选出其中一台实例当做主节点,其余的为从节点。主节点的每次操作都会使用`gRPC`接口同步到其他从节点上;从节点的写操作会使用`gRPC`请求到主节点上再同步到其他从节点上。以尽量达到高可用和数据的一致性。
20+
21+
22+
## 基本架构
23+
24+
现行阶段优先实现功能,未来可能会根据driver的权重指定优先获取顺序。
25+
当前版本的优先顺序按实例化client时指定的driver顺序。
26+
```go
27+
// 实例化一个以redis驱动为优先获取,内存驱动为后取的客户端
28+
client := jcache.NewClient(driver.NewRedis(), driver.NewMemory())
29+
30+
31+
// 实例化一个以内存驱动为优先获取,redis驱动为后取的客户端
32+
client := jcache.NewClient(driver.NewMemory(), driver.NewRedis())
33+
```
34+
### 基本架构图
35+
![](./assets/架构图.jpeg)
36+
## 进度
37+
38+
- [x] Redis驱动支持
39+
- [x] 本机内存驱动支持
40+
- [x] 单机模式支持
41+
- [x] 分布式模式支持
42+
- [x] 从节点的增量同步
43+
- [ ] 节点的全量同步
44+
45+
## 案例
46+
```shell
47+
go get github.com/jerbe/jcache/v2
48+
```
49+
50+
```go
51+
import (
52+
"time"
53+
54+
"github.com/jerbe/jcache/v2"
55+
"github.com/jerbe/jcache/v2/driver"
56+
)
57+
58+
func main(){
59+
// 实例化一个以内存作为驱动的缓存客户端
60+
client := jcache.NewClient()
61+
62+
// 实例化一个分布式的内存驱动缓存客户端
63+
cfg := driver.DistributeMemoryConfig{
64+
Port: 10080, // 用于启动grpc服务端口,同机器请设置不同端口
65+
Prefix: "/prefix", //根据自己的业务设置对应前缀
66+
// EtcdCfg 根据自己部署的ETCD服务设置对应配置
67+
EtcdCfg: clientv3.Config{
68+
Endpoints: []string{"127.0.0.1:2379"}
69+
}
70+
}
71+
client := driver.NewDistributeMemory(cfg)
72+
73+
74+
75+
// 支持所有操作的客户端,包括 String,Hash,List
76+
client := jcache.NewClient(driver.NewMemory())
77+
client.Set(context.Background(),"hello","world", time.Hour)
78+
client.Get(context.Background(),"hello")
79+
client.MGet(context.Background(),"hello","hi")
80+
...
81+
82+
// 仅支持 String 操作的客户端
83+
stringClient := jcache.NewStringClien(driver.NewMemory());
84+
stringClient.Set(context.Background(),"hello","world", time.Hour)
85+
stringClient.Get(context.Background(),"hello")
86+
stringClient.MGet(context.Background(),"hello","hi")
87+
...
88+
89+
// 仅支持 Hash 操作的客户端
90+
hashClient := jcache.NewHashClient(driver.NewMemory());
91+
hashClient.HSet(context.Background(),"hello","world","boom")
92+
hashClient.HGet(context.Background(),"hello","world")
93+
...
94+
95+
// 仅支持 List 操作的客户端
96+
listClient := jcache.NewListClient(driver.NewMemory());
97+
listClient.Push(context.Background(),"hello","world")
98+
listClient.Pop(context.Background(),"hello")
99+
listClient.Shift(context.Background(),"hello")
100+
}
101+
```

0 commit comments

Comments
 (0)