gRPC-cache

栏目: IT技术 · 发布时间: 4年前

内容简介:Go in memory cache using gRPC to generate API. Functionalities includeOnce you've cloned this repo, run these commands in this directory:

gRPC-cache

In memory cache, using gRPC

Contents

About

Go in memory cache using gRPC to generate API. Functionalities include

  • Adding/Replacing key/value
  • Getting value using a key
  • Getting all keys
  • Deleting a particular key
  • Deleting all keys
  • Concurrency safe and on client side calls can be made using goroutines

Requirements

Getting Started

Once you've cloned this repo, run these commands in this directory:

# Only needed the first time:
$ make build

# Then run to start server
$ ./server-cache --help

Usage of ./server-cache:
  -addr string
      Address on which you want to run server (default ":5001")
  -cln int
      Cleanup interval duration of expired cache is 5 min (default 5)
  -exp int
      Default expiration duration of cache is 10 min (default 10)

# To use client
$ ./client-cache --help

Usage of ./client-cache:
  -addr string
      Address on which you want to run server (default ":5001")

Usage

You can run server in 2 ways either using local setup or docker.

Local

  • Start your server ./server-cache or make server
  • ./server-cache -addr=":5001" to run server on port 5001

Docker

make docker
make dockerServer

After running the server, start your client ./client-cache or make client in a different terminal

  • ./client-cache -addr=":5001" is server is running running on port 5001

API

Proto syntax proto3 is used. You can find the proto file here

Add

This is used to add key/value to the cache

func (c Cache) Add(ctx context.Context, item *api.Item) (*api.Item, error)

Get

This is used to get key value pair for a particular key

func (c Cache) Get(ctx context.Context, args *api.GetKey) (*api.Item, error)

GetAllItems

Used to get all key value pairs

func (c Cache) GetAllItems(ctx context.Context, in *empty.Empty) (*api.AllItems, error)

DeleteKey

Used to delete item by a particular key from the cache

func (c Cache) DeleteKey(ctx context.Context, args *api.GetKey) (*api.Success, error)

DeleteAll

Used to clear the whole cache

func (c Cache) DeleteAll(ctx context.Context, in *empty.Empty) (*api.Success, error)

Testing

After running make build just run make test to run the tests. It has coverage of 91.2%

go test api/server/* -v -cover -race
=== RUN   TestAdd
--- PASS: TestAdd (0.04s)
=== RUN   TestGet
--- PASS: TestGet (0.03s)
=== RUN   TestGetAllItems
--- PASS: TestGetAllItems (0.01s)
=== RUN   TestDeleteKey
--- PASS: TestDeleteKey (0.01s)
=== RUN   TestDeleteAll
--- PASS: TestDeleteAll (0.01s)
=== RUN   TestGetDeletedKey
--- PASS: TestGetDeletedKey (0.01s)
=== RUN   TestDeleteKeyByExpiration
--- PASS: TestDeleteKeyByExpiration (2.01s)
PASS
coverage: 91.2% of statements
ok  	command-line-arguments	3.617s	coverage: 91.2% of statements

Example

Please refer to examples directory for more information


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

简约至上

简约至上

[英] Giles Colborne / 李松峰、秦绪文 / 人民邮电出版社 / 2011-1-1 / 35.00

追求简单易用是人类的本性,无论是互联网产品。还是移动应用。亦或其他交互式设计,简单易用始终都是赢得用户的关键。同时,简单易用的程度也与产品寿命的长短密切相关。在《简约至上:交互式设计四策略》中,作者Giles托20多年交互式设计的探索与实践。提出了合理删除、分层组织、适时隐藏和巧妙转移这四个达成简约至上的终极策略,讲述了为什么应该站在主流用户一边,以及如何从他们的真实需求和期望出发,简化设计,提升......一起来看看 《简约至上》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具