# Godis
![license](https://img.shields.io/github/license/HDT3213/godis)
[![Build Status](https://github.com/hdt3213/godis/actions/workflows/coverall.yml/badge.svg)](https://github.com/HDT3213/godis/actions?query=branch%3Amaster)
[![Coverage Status](https://coveralls.io/repos/github/HDT3213/godis/badge.svg?branch=master)](https://coveralls.io/github/HDT3213/godis?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/HDT3213/godis)](https://goreportcard.com/report/github.com/HDT3213/godis)
[![Go Reference](https://pkg.go.dev/badge/github.com/hdt3213/godis.svg)](https://pkg.go.dev/github.com/hdt3213/godis)
<br>
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go)
[中文版](https://github.com/hdt3213/godis/blob/master/README_CN.md)
`Godis` is a golang implementation of Redis Server, which intents to provide an example of writing a high concurrent
middleware using golang.
Key Features:
- Support string, list, hash, set, sorted set, bitmap
- Multi Database and `SELECT` command
- TTL
- Publish/Subscribe
- GEO
- AOF and AOF Rewrite
- RDB read and write
- MULTI Commands Transaction is Atomic and Isolated. If any errors are encountered during execution, godis will rollback
the executed commands
- Replication (experimental)
- Server-side Cluster which is transparent to client. You can connect to any node in the cluster to
access all data in the cluster.
- Use the raft algorithm to maintain cluster metadata. (experimental)
- `MSET`, `MSETNX`, `DEL`, `Rename`, `RenameNX` command is supported and atomically executed in cluster mode, allow over multi node
- `MULTI` Commands Transaction is supported within slot in cluster mode
- Concurrent Core, so you don't have to worry about your commands blocking the server too much.
If you could read Chinese, you can find more details in [My Blog](https://www.cnblogs.com/Finley/category/1598973.html).
## Get Started
You can get runnable program in the releases of this repository, which supports Linux and Darwin system.
```bash
./godis-darwin
./godis-linux
```
![](https://i.loli.net/2021/05/15/oQM1yZ6pWm3AIEj.png)
You could use redis-cli or other redis client to connect godis server, which listens on 0.0.0.0:6399 on default mode.
![](https://i.loli.net/2021/05/15/7WquEgonzY62sZI.png)
The program will try to read config file path from environment variable `CONFIG`.
If environment variable is not set, then the program try to read `redis.conf` in the working directory.
If there is no such file, then the program will run with default config.
### cluster mode
Godis can work in cluster mode, please append following lines to redis.conf file
```ini
peers localhost:7379,localhost:7389 // other node in cluster
self localhost:6399 // self address
```
We provide node1.conf and node2.conf for demonstration. use following command line to start a two-node-cluster:
```bash
CONFIG=node1.conf ./godis-darwin &
CONFIG=node2.conf ./godis-darwin &
```
Connect to a node in the cluster to access all data in the cluster:
```cmd
redis-cli -p 6399
```
## Supported Commands
See: [commands.md](https://github.com/HDT3213/godis/blob/master/commands.md)
## Benchmark
Environment:
Go version:1.17
System: macOS Catalina 10.15.7
CPU: 2.6GHz 6-Core Intel Core i7
Memory: 16 GB 2667 MHz DDR4
Performance report by redis-benchmark:
```
PING_INLINE: 87260.03 requests per second
PING_BULK: 89206.06 requests per second
SET: 85034.02 requests per second
GET: 87565.68 requests per second
INCR: 91157.70 requests per second
LPUSH: 90334.23 requests per second
RPUSH: 90334.23 requests per second
LPOP: 90334.23 requests per second
RPOP: 90415.91 requests per second
SADD: 90909.09 requests per second
HSET: 84104.29 requests per second
SPOP: 82918.74 requests per second
LPUSH (needed to benchmark LRANGE): 78247.26 requests per second
LRANGE_100 (first 100 elements): 26406.13 requests per second
LRANGE_300 (first 300 elements): 11307.10 requests per second
LRANGE_500 (first 450 elements): 7968.13 requests per second
LRANGE_600 (first 600 elements): 6092.73 requests per second
MSET (10 keys): 65487.89 requests per second
```
## Todo List
+ [x] `Multi` Command
+ [x] `Watch` Command and CAS support
+ [ ] Stream support
+ [x] RDB file loader
+ [ ] Master-Slave mode
+ [ ] Sentinel
## Read My Code
If you want to read my code in this repository, here is a simple guidance.
- project root: only the entry point
- config: config parser
- interface: some interface definitions
- lib: some utils, such as logger, sync utils and wildcard
I suggest focusing on the following directories:
- tcp: the tcp server
- redis: the redis protocol parser
- datastruct: the implements of data structures
- dict: a concurrent hash map
- list: a linked list
- lock: it is used to lock keys to ensure thread safety
- set: a hash set based on map
- sortedset: a sorted set implements based on skiplist
- database: the core of storage engine
- server.go: a standalone redis server, with multiple database
- database.go: data structure and base functions of single database
- exec.go: the gateway of database
- router.go: the command table
- keys.go: handlers for keys commands
- string.go: handlers for string commands
- list.go: handlers for list commands
- hash.go: handlers for hash commands
- set.go: handlers for set commands
- sortedset.go: handlers for sorted set commands
- pubsub.go: implements of publish / subscribe
- aof.go: implements of AOF persistence and rewrite
- geo.go: implements of geography features
- sys.go: authentication and other system function
- transaction.go: local transaction
- cluster:
- cluster.go: entrance of cluster mode
- com.go: communication within nodes
- del.go: atomic implementation of `delete` command in cluster
- keys.go: keys command
- mset.go: atomic implementation of `mset` command in cluster
- multi.go: entrance of distributed transaction
- pubsub.go: pub/sub in cluster
- rename.go: `rename` command in cluster
- tcc.go: try-commit-catch distributed transaction implementation
- aof: AOF persistence
# License
This project is licensed under the [GPL license](https://github.com/hdt3213/godis/blob/master/LICENSE).
没有合适的资源?快使用搜索试试~ 我知道了~
Golang 实现了 Redis 服务器和集群 Go语言实现的Redis服务器和遍布各处.zip
共156个文件
go:138个
conf:4个
sh:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 169 浏览量
2024-12-02
20:25:51
上传
评论
收藏 199KB ZIP 举报
温馨提示
Gordislish Version 简体中文Godis是Redis Server的golang实现,旨在提供使用golang编写高并发中间件的示例。主要特点支持字符串、列表、哈希、集合、有序集合、位图多数据库和SELECT命令TTL发布/订阅地理区域AOF 和 AOF 重写RDB 读写多命令事务是原子的和隔离的。如果在执行过程中遇到任何错误,godis 将回滚已执行的命令复制(实验)服务器端集群对客户端是透明的,你可以连接到集群中的任何节点来访问集群中的所有数据。使用 raft 算法来维护集群元数据。(实验)MSET,,,,命令在集群模式下受支持并原子执行,允许在多个MSETNX节点DEL上RenameRenameNXMULTI集群模式下支持槽内命令事务并发核心,因此您不必担心您的命令过多地阻塞服务器。如果您能读懂中文,您可以在我的博客中找到更多详细信息。立即开始您可以在此存储库的发布版本中获取可运行的程序,该版本支持 Linux 和 Darwin 系统。./godis-darwin./godis-linux
资源推荐
资源详情
资源评论
收起资源包目录
Golang 实现了 Redis 服务器和集群 Go语言实现的Redis服务器和遍布各处.zip (156个子文件)
node3.conf 184B
node2.conf 184B
node1.conf 177B
redis.conf 151B
.gitignore 269B
raft.go 28KB
sortedset_test.go 28KB
string_test.go 26KB
string.go 25KB
sortedset.go 24KB
list_test.go 18KB
hash.go 15KB
list.go 15KB
keys.go 14KB
concurrent_test.go 14KB
replication_master.go 14KB
replication_slave.go 13KB
server.go 13KB
keys_test.go 13KB
hash_test.go 12KB
set.go 12KB
concurrent.go 10KB
set_test.go 8KB
quicklist.go 8KB
aof.go 8KB
geo.go 8KB
replication_master_test.go 8KB
database.go 8KB
skiplist.go 8KB
aof_test.go 7KB
cluster.go 7KB
tcc.go 7KB
sortedset.go 7KB
tx_utils_test.go 6KB
linked_test.go 6KB
copy_test.go 6KB
quicklist_test.go 6KB
topo.go 5KB
parser.go 5KB
raft_snapshot.go 5KB
linked.go 5KB
topo_gcluster.go 5KB
mset.go 5KB
rename.go 5KB
multi.go 5KB
transaction.go 5KB
rdb.go 5KB
systemcmd.go 5KB
conn.go 5KB
client.go 5KB
assert.go 5KB
commandinfo.go 5KB
logger.go 5KB
cluster_helper.go 4KB
border.go 4KB
transaction_test.go 4KB
replication_slave_test.go 4KB
config.go 4KB
pubsub.go 4KB
utils_test.go 4KB
copy.go 4KB
tx_utils.go 4KB
reply.go 4KB
topo_test.go 4KB
lock_map.go 4KB
rewrite.go 4KB
com_factory.go 4KB
raft_event.go 3KB
router.go 3KB
multi_test.go 3KB
timewheel.go 3KB
set.go 3KB
wildcard_test.go 3KB
persistence.go 3KB
bitmap_test.go 3KB
neighbor.go 3KB
simple.go 3KB
client_test.go 3KB
geo_test.go 3KB
marshal.go 3KB
persistence_test.go 3KB
pool_test.go 3KB
server.go 3KB
com.go 3KB
systemcmd_test.go 3KB
pool.go 3KB
router.go 2KB
topo_utils.go 2KB
geohash.go 2KB
server.go 2KB
utils.go 2KB
errors.go 2KB
rename_test.go 2KB
utils.go 2KB
parser_test.go 2KB
consts.go 2KB
fake.go 2KB
cluster_helper_test.go 2KB
echo.go 2KB
bitmap.go 2KB
共 156 条
- 1
- 2
资源评论
赵闪闪168
- 粉丝: 1660
- 资源: 5391
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功