-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
58 lines (47 loc) · 1.04 KB
/
context.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
package main
import (
"fmt"
"github.com/gushitong/rekkles/ut"
"github.com/tidwall/redcon"
)
type Context struct {
Authenticated bool
ConnectionID int64
}
type aryConnection struct {
redcon.Conn
}
func (c aryConnection) Authenticated() bool {
return c.Context() != nil && c.Context().(*Context).Authenticated
}
func (c aryConnection) WriteErr(err error) {
c.WriteError(fmt.Sprint(err))
}
func (c aryConnection) WriteBool(v bool) {
if v {
c.WriteInt(1)
} else {
c.WriteInt(0)
}
}
type aryCommand struct {
Raw []byte
Args [][]byte
}
func (aryCmd aryCommand) StringKey() []byte {
return NewStringEncoder(aryCmd.Args[0]).Encode()
}
func (aryCmd aryCommand) HashKey() ([]byte, error) {
encoder, err := NewHashEncoder(aryCmd.Args[0])
return encoder.Encode(aryCmd.Args[1]), err
}
func (aryCmd aryCommand) HashPrefix() ([]byte, error) {
encoder, err := NewHashEncoder(aryCmd.Args[0])
return encoder.Prefix(), err
}
func (aryCmd aryCommand) QueueKey() []byte {
return ut.ConcatBytearray(
[]byte{(byte)(SymbolQueue)},
aryCmd.Args[0],
)
}