reformat code

This commit is contained in:
hdt3213
2021-04-03 20:14:12 +08:00
parent bf913a5aca
commit bcf0cd5e92
54 changed files with 4887 additions and 4896 deletions

View File

@@ -2,11 +2,13 @@
[中文版](https://github.com/HDT3213/godis/blob/master/README_CN.md) [中文版](https://github.com/HDT3213/godis/blob/master/README_CN.md)
`Godis` is a simple implementation of Redis Server, which intents to provide an example of writing a high concurrent middleware using golang. `Godis` is a simple implementation of Redis Server, which intents to provide an example of writing a high concurrent
middleware using golang.
Please be advised, NEVER think about using this in production environment. Please be advised, NEVER think about using this in production environment.
This repository implemented most features of redis, including 5 data structures, ttl, publish/subscribe, AOF persistence and server side cluster mode. This repository implemented most features of redis, including 5 data structures, ttl, publish/subscribe, AOF persistence
and server side cluster mode.
If you could read Chinese, you can find more details in [My Blog](https://www.cnblogs.com/Finley/category/1598973.html). If you could read Chinese, you can find more details in [My Blog](https://www.cnblogs.com/Finley/category/1598973.html).
@@ -35,8 +37,7 @@ peers localhost:7379,localhost:7389 // other node in cluster
self localhost:6399 // self address self localhost:6399 // self address
``` ```
We provide node1.conf and node2.conf for demonstration. We provide node1.conf and node2.conf for demonstration. use following command line to start a two-node-cluster:
use following command line to start a two-node-cluster:
```bash ```bash
CONFIG=node1.conf ./godis-darwin & CONFIG=node1.conf ./godis-darwin &

View File

@@ -2,8 +2,8 @@ Godis 是一个用 Go 语言实现的 Redis 服务器。本项目旨在为尝试
**请注意:不要在生产环境使用使用此项目** **请注意:不要在生产环境使用使用此项目**
Godis 实现了 Redis 的大多数功能包括5种数据结构、TTL、发布订阅以及 AOF 持久化。可以在[我的博客](https://www.cnblogs.com/Finley/category/1598973.html)了解更多关于 Godis 的信息。 Godis 实现了 Redis 的大多数功能包括5种数据结构、TTL、发布订阅以及 AOF 持久化。可以在[我的博客](https://www.cnblogs.com/Finley/category/1598973.html)了解更多关于
Godis 的信息。
# 运行 Godis # 运行 Godis

View File

@@ -37,4 +37,3 @@ func RenameNx(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
} }
return cluster.Relay(srcPeer, c, args) return cluster.Relay(srcPeer, c, args)
} }

View File

@@ -1,9 +1,9 @@
package list package list
import ( import (
"testing"
"strconv" "strconv"
"strings" "strings"
"testing"
) )
func ToString(list *LinkedList) string { func ToString(list *LinkedList) string {

View File

@@ -106,7 +106,6 @@ func (locks *Locks)RLocks(keys ...string) {
} }
} }
func (locks *Locks) UnLocks(keys ...string) { func (locks *Locks) UnLocks(keys ...string) {
indices := locks.toLockIndices(keys, true) indices := locks.toLockIndices(keys, true)
for _, index := range indices { for _, index := range indices {

View File

@@ -6,7 +6,6 @@ const (
maxLevel = 16 maxLevel = 16
) )
type Element struct { type Element struct {
Member string Member string
Score float64 Score float64

View File

@@ -214,7 +214,6 @@ func (sortedSet *SortedSet) RemoveByScore(min *ScoreBorder, max *ScoreBorder)int
return int64(len(removed)) return int64(len(removed))
} }
/* /*
* 0-based rank, [start, stop) * 0-based rank, [start, stop)
*/ */

View File

@@ -1,8 +1,8 @@
package tcp package tcp
import ( import (
"net"
"context" "context"
"net"
) )
type HandleFunc func(ctx context.Context, conn net.Conn) type HandleFunc func(ctx context.Context, conn net.Conn)

View File

@@ -1,11 +1,11 @@
package files package files
import ( import (
"mime/multipart"
"io/ioutil"
"path"
"os"
"fmt" "fmt"
"io/ioutil"
"mime/multipart"
"os"
"path"
) )
func GetSize(f multipart.File) (int, error) { func GetSize(f multipart.File) (int, error) {

View File

@@ -15,5 +15,3 @@ func (b *AtomicBool)Set(v bool) {
atomic.StoreUint32((*uint32)(b), 0) atomic.StoreUint32((*uint32)(b), 0)
} }
} }

View File

@@ -310,7 +310,6 @@ func (client *Client) handleRead() error {
client.finishRequest(reply) client.finishRequest(reply)
} }
// finish reply // finish reply
expectedArgsCount = 0 expectedArgsCount = 0
receivedCount = 0 receivedCount = 0

View File

@@ -110,7 +110,6 @@ func (r *IntReply) ToBytes() []byte {
return []byte(":" + strconv.FormatInt(r.Code, 10) + CRLF) return []byte(":" + strconv.FormatInt(r.Code, 10) + CRLF)
} }
/* ---- Error Reply ---- */ /* ---- Error Reply ---- */
type ErrorReply interface { type ErrorReply interface {

View File

@@ -5,15 +5,15 @@ package tcp
*/ */
import ( import (
"net"
"context"
"bufio" "bufio"
"context"
"github.com/HDT3213/godis/src/lib/logger" "github.com/HDT3213/godis/src/lib/logger"
"sync"
"io"
"github.com/HDT3213/godis/src/lib/sync/atomic" "github.com/HDT3213/godis/src/lib/sync/atomic"
"time"
"github.com/HDT3213/godis/src/lib/sync/wait" "github.com/HDT3213/godis/src/lib/sync/wait"
"io"
"net"
"sync"
"time"
) )
type EchoHandler struct { type EchoHandler struct {
@@ -21,9 +21,8 @@ type EchoHandler struct {
closing atomic.AtomicBool closing atomic.AtomicBool
} }
func MakeEchoHandler()(*EchoHandler) { func MakeEchoHandler() *EchoHandler {
return &EchoHandler{ return &EchoHandler{}
}
} }
type Client struct { type Client struct {

View File

@@ -45,7 +45,6 @@ func ListenAndServe(cfg *Config, handler tcp.Handler) {
} }
}() }()
// listen port // listen port
logger.Info(fmt.Sprintf("bind: %s, start listening...", cfg.Address)) logger.Info(fmt.Sprintf("bind: %s, start listening...", cfg.Address))
defer func() { defer func() {