mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 16:57:06 +08:00
reformat code
This commit is contained in:
@@ -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 &
|
||||||
|
@@ -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
|
||||||
|
|
||||||
|
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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 {
|
||||||
|
@@ -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 {
|
||||||
|
@@ -6,7 +6,6 @@ const (
|
|||||||
maxLevel = 16
|
maxLevel = 16
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Element struct {
|
type Element struct {
|
||||||
Member string
|
Member string
|
||||||
Score float64
|
Score float64
|
||||||
|
@@ -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)
|
||||||
*/
|
*/
|
||||||
|
@@ -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)
|
||||||
|
@@ -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) {
|
||||||
|
@@ -15,5 +15,3 @@ func (b *AtomicBool)Set(v bool) {
|
|||||||
atomic.StoreUint32((*uint32)(b), 0)
|
atomic.StoreUint32((*uint32)(b), 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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
|
||||||
|
@@ -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 {
|
||||||
|
@@ -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 {
|
||||||
|
@@ -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() {
|
||||||
|
Reference in New Issue
Block a user