项目作者: andrei-punko

项目描述 :
Redis-like in-memory cache
高级语言: Go
项目地址: git://github.com/andrei-punko/go-cache.git
创建时间: 2019-10-06T15:35:29Z
项目社区:https://github.com/andrei-punko/go-cache

开源协议:MIT License

下载


Test Task (Juno Inc.): In-memory cache

Go CI with Gradle

Task definition taken from here

Description

Simple implementation of Redis-like in-memory cache

Desired features:

  • Key-value storage with string, lists, dict support
  • Per-key TTL
  • Operations:
    • Get
    • Set
    • Remove
  • Golang API client
  • Provide some tests, API spec, some deployment manual, some examples of client usages would be nice.

Optional features:

  • Telnet-like/HTTP-like API protocol
  • performance tests
  • Operations:
    • Keys

Build using Gradle

  1. ./gradlew goBuild

Result binaries will be placed into ./gogradle folder

Put application into Docker image:

  1. docker build -t apunko/go-cache .

Start application

Start application on default port 8000:

On Linux OS:

  1. ./.gogradle/linux_amd64_go-cache

On Win OS:

  1. ./.gogradle/windows_amd64_go-cache.exe

Start application on user defined port (8005 for example):

On Linux OS:

  1. ./.gogradle/linux_amd64_go-cache 8005

On Win OS:

  1. ./.gogradle/windows_amd64_go-cache.exe 8005

Start Docker container using docker command:

  1. docker run --rm -p 8000:8000 apunko/go-cache

Or start Docker container using docker-compose command:

  1. docker-compose up

Interact with application

Cache population with some key-value pairs:

  1. curl -i -X POST -H "Accept: application/json" -H "Content-Type: application/json" -d '{"value": "Ivan", "ttl": 60000000000}' http://localhost:8000/items/name
  1. curl -i -X POST -H "Accept: application/json" -H "Content-Type: application/json" -d '{"value": ["VISA", "Mastercard"], "ttl": 60000000000}' http://localhost:8000/items/cards
  1. curl -i -X POST -H "Accept: application/json" -H "Content-Type: application/json" -d '{"value": {"Math": "9", "English": "7"}, "ttl": 60000000000}' http://localhost:8000/items/marks

Getting value by key=name from cache:

  1. curl -i http://localhost:8000/items/name

Getting all keys from cache:

  1. curl -i http://localhost:8000/items/keys

Deletion of some key-value pair from cache for key=name:

  1. curl -i -X DELETE http://localhost:8000/items/name

Cache cleanup:

  1. curl -i -X DELETE http://localhost:8000/items/keys