Skip to content

Commit

Permalink
Refactor Redis server implementation and update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
diiyw committed Apr 19, 2024
1 parent 880bf89 commit 248e0e0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

English | [简体中文](https://github.com/diiyw/nodis/blob/main/README_zh-cn.md)

A Golang implemented Redis data structure.
It is a simple and easy to embed in your application.
Redis re-implemented using golang.
Simple way to embed in your application.

## Supported Data Types

Expand Down
2 changes: 1 addition & 1 deletion README_zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[English](https://github.com/diiyw/nodis/blob/main/README.md) | 简体中文

Nodis 是一个简单可嵌入到应用中内存数据库,实现Redis的数据结构
Nodis 是使用GO语言实现的、简单可嵌入到应用中内存数据库

## 支持的类型

Expand Down
40 changes: 20 additions & 20 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func keys(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
keys := n.Keys(pattern)
var k = make([]redis.Value, 0, len(keys))
for _, v := range keys {
k = append(k, redis.StringValue(v))
k = append(k, redis.BulkValue(v))
}
return redis.ArrayValue(k...)
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func typ(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
return redis.ErrorValue("TYPE requires at least one argument")
}
key := args[0].Bulk
return redis.StringValue(n.Type(key))
return redis.BulkValue(n.Type(key))
}

func scan(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
Expand All @@ -283,7 +283,7 @@ func scan(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
r[0] = redis.BulkValue(strconv.FormatInt(cursor, 10))
var k = make([]redis.Value, 0, len(keys))
for _, v := range keys {
k = append(k, redis.StringValue(v))
k = append(k, redis.BulkValue(v))
}
r[1] = redis.ArrayValue(k...)
return redis.ArrayValue(r...)
Expand Down Expand Up @@ -329,7 +329,7 @@ func setString(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
return redis.StringValue("OK")
}
if get != nil {
return redis.StringValue(string(get))
return redis.BulkValue(string(get))
}
return redis.StringValue("OK")
}
Expand Down Expand Up @@ -359,7 +359,7 @@ func getString(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
if v == nil {
return redis.NullValue()
}
return redis.StringValue(string(v))
return redis.BulkValue(string(v))
}

func setBit(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
Expand Down Expand Up @@ -470,7 +470,7 @@ func sDiff(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.SDiff(keys...)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(v))
r = append(r, redis.BulkValue(v))
}
return redis.ArrayValue(r...)
}
Expand All @@ -486,7 +486,7 @@ func sInter(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.SInter(keys...)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(v))
r = append(r, redis.BulkValue(v))
}
return redis.ArrayValue(r...)
}
Expand All @@ -513,7 +513,7 @@ func sMembers(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.SMembers(key)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(v))
r = append(r, redis.BulkValue(v))
}
return redis.ArrayValue(r...)
}
Expand Down Expand Up @@ -559,7 +559,7 @@ func hGet(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
}
key := args[0].Bulk
field := args[1].Bulk
return redis.StringValue(string(n.HGet(key, field)))
return redis.BulkValue(string(n.HGet(key, field)))
}

func hDel(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
Expand Down Expand Up @@ -590,7 +590,7 @@ func hKeys(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.HKeys(key)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(v))
r = append(r, redis.BulkValue(v))
}
return redis.ArrayValue(r...)
}
Expand All @@ -617,7 +617,7 @@ func hGetAll(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.HGetAll(key)
var r = make(map[string]redis.Value)
for k, v := range results {
r[k] = redis.StringValue(string(v))
r[k] = redis.BulkValue(string(v))
}
return redis.MapValue(r)
}
Expand Down Expand Up @@ -668,7 +668,7 @@ func hMGet(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.HMGet(key, fields...)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(string(v)))
r = append(r, redis.BulkValue(string(v)))
}
return redis.ArrayValue(r...)
}
Expand Down Expand Up @@ -728,7 +728,7 @@ func hVals(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.HVals(key)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(string(v)))
r = append(r, redis.BulkValue(string(v)))
}
return redis.ArrayValue(r...)
}
Expand Down Expand Up @@ -776,7 +776,7 @@ func lPop(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
}
var r = make([]redis.Value, 0, len(v))
for _, vv := range v {
r = append(r, redis.StringValue(string(vv)))
r = append(r, redis.BulkValue(string(vv)))
}
return redis.ArrayValue(r...)
}
Expand All @@ -799,7 +799,7 @@ func rPop(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
}
var r = make([]redis.Value, 0, len(v))
for _, vv := range v {
r = append(r, redis.StringValue(string(vv)))
r = append(r, redis.BulkValue(string(vv)))
}
return redis.ArrayValue(r...)
}
Expand Down Expand Up @@ -885,7 +885,7 @@ func lRange(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.LRange(key, start, end)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(string(v)))
r = append(r, redis.BulkValue(string(v)))
}
return redis.ArrayValue(r...)
}
Expand Down Expand Up @@ -1021,7 +1021,7 @@ func zRange(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.ZRange(key, start, stop)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(v))
r = append(r, redis.BulkValue(v))
}
return redis.ArrayValue(r...)
}
Expand All @@ -1044,7 +1044,7 @@ func zRevRange(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.ZRevRange(key, start, stop)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(v))
r = append(r, redis.BulkValue(v))
}
return redis.ArrayValue(r...)
}
Expand All @@ -1059,7 +1059,7 @@ func zRangeByScore(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value {
results := n.ZRangeByScore(key, min, max)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(v))
r = append(r, redis.BulkValue(v))
}
return redis.ArrayValue(r...)
}
Expand All @@ -1074,7 +1074,7 @@ func zRevRangeByScore(n *Nodis, cmd redis.Value, args []redis.Value) redis.Value
results := n.ZRevRangeByScore(key, min, max)
var r = make([]redis.Value, 0, len(results))
for _, v := range results {
r = append(r, redis.StringValue(v))
r = append(r, redis.BulkValue(v))
}
return redis.ArrayValue(r...)
}
Expand Down
2 changes: 0 additions & 2 deletions nodis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"os"
"strings"
"sync"
"time"

"github.com/diiyw/nodis/fs"
Expand All @@ -20,7 +19,6 @@ var (
)

type Nodis struct {
sync.RWMutex
options *Options
store *store
watchers []*watch.Watcher
Expand Down

0 comments on commit 248e0e0

Please sign in to comment.