github.com/hdt3213/godis@v1.2.9/README.md (about) 1 # Godis 2 3  4 [](https://github.com/HDT3213/godis/actions?query=branch%3Amaster) 5 [](https://coveralls.io/github/HDT3213/godis?branch=master) 6 [](https://goreportcard.com/report/github.com/HDT3213/godis) 7 [](https://pkg.go.dev/github.com/hdt3213/godis) 8 <br> 9 [](https://github.com/avelino/awesome-go) 10 11 [中文版](https://github.com/hdt3213/godis/blob/master/README_CN.md) 12 13 `Godis` is a golang implementation of Redis Server, which intents to provide an example of writing a high concurrent 14 middleware using golang. 15 16 Key Features: 17 18 - Support string, list, hash, set, sorted set, bitmap 19 - Multi Database and `SELECT` command 20 - TTL 21 - Publish/Subscribe 22 - GEO 23 - AOF and AOF Rewrite 24 - RDB read and write 25 - MULTI Commands Transaction is Atomic and Isolated. If any errors are encountered during execution, godis will rollback 26 the executed commands 27 - Replication (experimental) 28 - Server-side Cluster which is transparent to client. You can connect to any node in the cluster to 29 access all data in the cluster. 30 - `MSET`, `MSETNX`, `DEL`, `Rename`, `RenameNX` command is supported and atomically executed in cluster mode, allow over multi node 31 - `MULTI` Commands Transaction is supported within slot in cluster mode 32 - Concurrent Core, so you don't have to worry about your commands blocking the server too much. 33 34 If you could read Chinese, you can find more details in [My Blog](https://www.cnblogs.com/Finley/category/1598973.html). 35 36 ## Get Started 37 38 You can get runnable program in the releases of this repository, which supports Linux and Darwin system. 39 40 ```bash 41 ./godis-darwin 42 ./godis-linux 43 ``` 44 45  46 47 You could use redis-cli or other redis client to connect godis server, which listens on 0.0.0.0:6399 on default mode. 48 49  50 51 The program will try to read config file path from environment variable `CONFIG`. 52 53 If environment variable is not set, then the program try to read `redis.conf` in the working directory. 54 55 If there is no such file, then the program will run with default config. 56 57 ### cluster mode 58 59 Godis can work in cluster mode, please append following lines to redis.conf file 60 61 ```ini 62 peers localhost:7379,localhost:7389 // other node in cluster 63 self localhost:6399 // self address 64 ``` 65 66 We provide node1.conf and node2.conf for demonstration. use following command line to start a two-node-cluster: 67 68 ```bash 69 CONFIG=node1.conf ./godis-darwin & 70 CONFIG=node2.conf ./godis-darwin & 71 ``` 72 73 Connect to a node in the cluster to access all data in the cluster: 74 75 ```cmd 76 redis-cli -p 6399 77 ``` 78 79 ## Supported Commands 80 81 See: [commands.md](https://github.com/HDT3213/godis/blob/master/commands.md) 82 83 ## Benchmark 84 85 Environment: 86 87 Go version:1.17 88 89 System: macOS Catalina 10.15.7 90 91 CPU: 2.6GHz 6-Core Intel Core i7 92 93 Memory: 16 GB 2667 MHz DDR4 94 95 Performance report by redis-benchmark: 96 97 ``` 98 PING_INLINE: 87260.03 requests per second 99 PING_BULK: 89206.06 requests per second 100 SET: 85034.02 requests per second 101 GET: 87565.68 requests per second 102 INCR: 91157.70 requests per second 103 LPUSH: 90334.23 requests per second 104 RPUSH: 90334.23 requests per second 105 LPOP: 90334.23 requests per second 106 RPOP: 90415.91 requests per second 107 SADD: 90909.09 requests per second 108 HSET: 84104.29 requests per second 109 SPOP: 82918.74 requests per second 110 LPUSH (needed to benchmark LRANGE): 78247.26 requests per second 111 LRANGE_100 (first 100 elements): 26406.13 requests per second 112 LRANGE_300 (first 300 elements): 11307.10 requests per second 113 LRANGE_500 (first 450 elements): 7968.13 requests per second 114 LRANGE_600 (first 600 elements): 6092.73 requests per second 115 MSET (10 keys): 65487.89 requests per second 116 ``` 117 118 ## Todo List 119 120 + [x] `Multi` Command 121 + [x] `Watch` Command and CAS support 122 + [ ] Stream support 123 + [x] RDB file loader 124 + [ ] Master-Slave mode 125 + [ ] Sentinel 126 127 ## Read My Code 128 129 If you want to read my code in this repository, here is a simple guidance. 130 131 - project root: only the entry point 132 - config: config parser 133 - interface: some interface definitions 134 - lib: some utils, such as logger, sync utils and wildcard 135 136 I suggest focusing on the following directories: 137 138 - tcp: the tcp server 139 - redis: the redis protocol parser 140 - datastruct: the implements of data structures 141 - dict: a concurrent hash map 142 - list: a linked list 143 - lock: it is used to lock keys to ensure thread safety 144 - set: a hash set based on map 145 - sortedset: a sorted set implements based on skiplist 146 - database: the core of storage engine 147 - server.go: a standalone redis server, with multiple database 148 - database.go: data structure and base functions of single database 149 - exec.go: the gateway of database 150 - router.go: the command table 151 - keys.go: handlers for keys commands 152 - string.go: handlers for string commands 153 - list.go: handlers for list commands 154 - hash.go: handlers for hash commands 155 - set.go: handlers for set commands 156 - sortedset.go: handlers for sorted set commands 157 - pubsub.go: implements of publish / subscribe 158 - aof.go: implements of AOF persistence and rewrite 159 - geo.go: implements of geography features 160 - sys.go: authentication and other system function 161 - transaction.go: local transaction 162 - cluster: 163 - cluster.go: entrance of cluster mode 164 - com.go: communication within nodes 165 - del.go: atomic implementation of `delete` command in cluster 166 - keys.go: keys command 167 - mset.go: atomic implementation of `mset` command in cluster 168 - multi.go: entrance of distributed transaction 169 - pubsub.go: pub/sub in cluster 170 - rename.go: `rename` command in cluster 171 - tcc.go: try-commit-catch distributed transaction implementation 172 - aof: AOF persistence 173 174 # License 175 176 This project is licensed under the [GPL license](https://github.com/hdt3213/godis/blob/master/LICENSE).