/cache-service

A full-fledged RPC service which would allow to get and set data to a Redis cache

Primary LanguageGoApache License 2.0Apache-2.0

cache-service

Development Environment

OS
ProductName:	macOS
ProductVersion:	12.0
Gopath
GOPATH="/Users/minhtet/go"
local repo dir
/Users/minhtet/dev/cache-service

Setup

  1. Clone the Rep
  2. Start Redis server
    chmod +x initialize_redis.sh && ./initialize_redis.sh
  3. build server
    go build -o ./build/rpcServer ./server/handlers/*.go
  4. build client
    go build -o ./build/rpcClient ./client/*.go

Usage

Programming interface

1. Set Cache
var ctx = context.Background()
_, err := c.Set(ctx, &pb.CacheSetInput{Key: "hello", Value: []byte("123")})
if err != nil {
	panic(err)
}
2. Get Cache
var ctx = context.Background()
resp, err := c.Get(ctx, &pb.CacheGetInput{Key: "hello"})
if err != nil {
	panic(err)
}
fmt.Println(resp)
3. Set User Cache
_, err = c.SetUser(ctx, &pb.User{
	Name:     "john",
	Class:    "V",
	Rollnum:  22,
	Metadata: []byte("smart student"),
})
if err != nil {
	panic(err)
}
4. Get User Cache
user, err := c.GetUser(ctx, &pb.GetUserInput{
		Name:    "john",
		Class:   "V",
		Rollnum: 22,
})
if err != nil {
	panic(err)
}

fmt.Println(user)

Console

1. Run server

./build/rpcServer

2. Set Cache

./build/rpcClient -set your_key your_value

3. Get Cache

./build/rpcClient -get your_key

4. Set User Cache

./build/rpcClient -set-user john V 22 "smart student"

5. Get User Cache

./build/rpcClient -get-user john V 22