forked from alash3al/redix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvars.go
141 lines (125 loc) · 3.89 KB
/
vars.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2018 The Redix Authors. All rights reserved.
// Use of this source code is governed by a Apache 2.0
// license that can be found in the LICENSE file.
package main
import (
"flag"
"net/url"
"runtime"
"sync"
"github.com/alash3al/go-pubsub"
"github.com/bwmarrin/snowflake"
)
var (
flagRESPListenAddr = flag.String("resp-addr", ":6380", "the address of resp server")
flagHTTPListenAddr = flag.String("http-addr", ":7090", "the address of the http server")
flagStorageDir = flag.String("storage", "./redix-data", "the storage directory")
flagEngine = flag.String("engine", "leveldb", "the storage engine to be used")
flagEngineOptions = flag.String("engine-options", "", "options related to used engine in the url query format, i.e (opt1=val2&opt2=val2)")
flagWorkers = flag.Int("workers", runtime.NumCPU(), "the default workers number")
flagVerbose = flag.Bool("verbose", false, "verbose or not")
flagACK = flag.Bool("ack", true, "acknowledge write or return immediately")
)
var (
databases *sync.Map
changelog *pubsub.Broker
webhooks *sync.Map
websockets *sync.Map
snowflakeGenerator *snowflake.Node
kvjobs chan func()
)
var (
commands = map[string]CommandHandler{
// strings
"set": setCommand,
"mset": msetCommand,
"get": getCommand,
"mget": mgetCommand,
"del": delCommand,
"exists": existsCommand,
"incr": incrCommand,
"ttl": ttlCommand,
"keys": keysCommand,
// lists
"lpush": lpushCommand,
"lpushu": lpushuCommand,
"lrange": lrangeCommand,
"lrem": lremCommand,
"lcount": lcountCommand,
"lcard": lcountCommand,
"lsum": lsumCommand,
"lavg": lavgCommand,
"lmin": lminCommand,
"lmax": lmaxCommand,
"lsrch": lsearchCommand,
"lsrchcount": lsearchcountCommand,
// sets (list alias)
"sadd": lpushuCommand,
"smembers": lrangeCommand,
"srem": lremCommand,
"scard": lcountCommand,
"sscan": lrangeCommand,
// hashes
"hset": hsetCommand,
"hget": hgetCommand,
"hdel": hdelCommand,
"hgetall": hgetallCommand,
"hkeys": hkeysCommand,
"hmset": hmsetCommand,
"hexists": hexistsCommand,
"hincr": hincrCommand,
"httl": httlCommand,
"hlen": hlenCommand,
// pubsub
"publish": publishCommand,
"subscribe": subscribeCommand,
"webhookset": webhooksetCommand,
"webhookdel": webhookdelCommand,
"websocketopen": websocketopenCommand,
"websocketclose": websocketcloseCommand,
// utils
"encode": encodeCommand,
"uuidv4": uuid4Command,
"uniqid": uniqidCommand,
"randstr": randstrCommand,
"randint": randintCommand,
"time": timeCommand,
"dbsize": dbsizeCommand,
"gc": gcCommand,
"info": infoCommand,
"echo": echoCommand,
"flushdb": flushdbCommand,
"flushall": flushallCommand,
// ratelimit
"ratelimitset": ratelimitsetCommand,
"ratelimittake": ratelimittakeCommand,
"ratelimitget": ratelimitgetCommand,
}
)
var (
supportedEngines = map[string]bool{
"badgerdb": true,
"boltdb": true,
"leveldb": true,
"null": true,
"sqlite": true,
}
engineOptions = url.Values{}
defaultPubSubAllTopic = "*"
)
const (
redixVersion = "1.10"
redixBrand = `
_______ _______ ______ _________
( ____ )( ____ \( __ \ \__ __/|\ /|
| ( )|| ( \/| ( \ ) ) ( ( \ / )
| (____)|| (__ | | ) | | | \ (_) /
| __)| __) | | | | | | ) _ (
| (\ ( | ( | | ) | | | / ( ) \
| ) \ \__| (____/\| (__/ )___) (___( / \ )
|/ \__/(_______/(______/ \_______/|/ \|
A high-concurrency standalone NoSQL datastore with the support for redis protocol
and multiple backends/engines, also there is a native support for
real-time apps via webhook & websockets besides the basic redis channels.
`
)