forked from redis-go/redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.go
48 lines (44 loc) · 1.09 KB
/
serve.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
package redis
import (
"crypto/tls"
"github.com/redis-go/redcon"
"time"
)
// Run runs the default redis server.
// Initializes the default redis if not already.
func Run(addr string) error {
return Default().Run(addr)
}
// Run runs the redis server.
func (r *Redis) Run(addr string) error {
go r.KeyExpirer().Start(100*time.Millisecond, 20, 25)
return redcon.ListenAndServe(
addr,
func(conn redcon.Conn, cmd redcon.Command) {
r.HandlerFn()(r.NewClient(conn), cmd)
},
func(conn redcon.Conn) bool {
return r.AcceptFn()(r.NewClient(conn))
},
func(conn redcon.Conn, err error) {
r.OnCloseFn()(r.NewClient(conn), err)
},
)
}
// Run runs the redis server with tls.
func (r *Redis) RunTLS(addr string, tls *tls.Config) error {
go r.KeyExpirer().Start(100*time.Millisecond, 20, 25)
return redcon.ListenAndServeTLS(
addr,
func(conn redcon.Conn, cmd redcon.Command) {
r.HandlerFn()(r.NewClient(conn), cmd)
},
func(conn redcon.Conn) bool {
return r.AcceptFn()(r.NewClient(conn))
},
func(conn redcon.Conn, err error) {
r.OnCloseFn()(r.NewClient(conn), err)
},
tls,
)
}