summaryrefslogtreecommitdiff
path: root/plugins/kv/rpc.go
blob: 751f0d124741525e2bca62547869a5327cb4af15 (plain)
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
package kv

import (
	"github.com/spiral/errors"
	"github.com/spiral/roadrunner/v2/plugins/logger"
)

// Wrapper for the plugin
type RPCServer struct {
	// svc is a plugin implementing Storage interface
	svc Storage
	// Logger
	log logger.Logger
}

// NewRPCServer construct RPC server for the particular plugin
func NewRPCServer(srv Storage, log logger.Logger) *RPCServer {
	return &RPCServer{
		svc: srv,
		log: log,
	}
}

// data Data
func (r *RPCServer) Has(in []string, res *map[string]bool) error {
	const op = errors.Op("rpc server Has")
	ret, err := r.svc.Has(in...)
	if err != nil {
		return errors.E(op, err)
	}

	// update the value in the pointer
	*res = ret
	return nil
}

// in SetData
func (r *RPCServer) Set(in []Item, ok *bool) error {
	const op = errors.Op("rpc server Set")

	err := r.svc.Set(in...)
	if err != nil {
		return errors.E(op, err)
	}

	*ok = true
	return nil
}

// in Data
func (r *RPCServer) MGet(in []string, res *map[string]interface{}) error {
	const op = errors.Op("rpc server MGet")
	ret, err := r.svc.MGet(in...)
	if err != nil {
		return errors.E(op, err)
	}

	// update return value
	*res = ret
	return nil
}

// in Data
func (r *RPCServer) MExpire(in []Item, ok *bool) error {
	const op = errors.Op("rpc server MExpire")

	err := r.svc.MExpire(in...)
	if err != nil {
		return errors.E(op, err)
	}

	*ok = true
	return nil
}

// in Data
func (r *RPCServer) TTL(in []string, res *map[string]interface{}) error {
	const op = errors.Op("rpc server TTL")

	ret, err := r.svc.TTL(in...)
	if err != nil {
		return errors.E(op, err)
	}

	*res = ret
	return nil
}

// in Data
func (r *RPCServer) Delete(in []string, ok *bool) error {
	const op = errors.Op("rpc server Delete")
	err := r.svc.Delete(in...)
	if err != nil {
		return errors.E(op, err)
	}
	*ok = true
	return nil
}

// in string, storages
func (r *RPCServer) Close(storage string, ok *bool) error {
	const op = errors.Op("rpc server Close")
	err := r.svc.Close()
	if err != nil {
		return errors.E(op, err)
	}
	*ok = true

	return nil
}