Skip to content

Latest commit

 

History

History
83 lines (57 loc) · 2.32 KB

File metadata and controls

83 lines (57 loc) · 2.32 KB

State management demo with redis

Quick start

This example shows how to call redis through Layotto to add, delete, modify and query status data.

The architecture of this example is shown in the figure below, and the started processes are: redis, Layotto, client program

img.png

Deploy redis using Docker

  1. Get the latest version of Redis docker image

Here we pull the latest version of the official image:

docker pull redis:latest
  1. View the local mirror

Use the following command to check if redis is installed:

docker images

img.png

  1. Run the container

After the installation is complete, we can use the following command to run the redis container:

docker run -itd --name redis-test -p 6380:6379 redis

Parameter Description:

-p 6380:6379: Map port 6379 of the container to port 6380 of the host. The outside can directly access the Redis service through the host ip:6380.

Run Layotto

After downloading the project code to the local, enter the code directory and compile:

cd ${projectpath}/cmd/layotto
go build

The layotto file will be generated in the directory, run it:

./layotto start -c ../../configs/config_state_redis.json

Run the client program, call Layotto to add, delete, modify and query

 cd ${projectpath}/demo/state/redis/
 go build -o client
 ./client

If the following information is printed, the call is successful:

SaveState succeeded.key:key1 , value: hello world 
GetState succeeded.[key:key1 etag:1]: hello world
SaveBulkState succeeded.[key:key1 etag:2]: hello world
SaveBulkState succeeded.[key:key2 etag:2]: hello world
GetBulkState succeeded.key:key1,value:hello world
GetBulkState succeeded.key:key3,value:
GetBulkState succeeded.key:key2,value:hello world
GetBulkState succeeded.key:key5,value:
GetBulkState succeeded.key:key4,value:
DeleteState succeeded.key:key1
DeleteState succeeded.key:key2

Next step

The client demo uses the golang version SDK provided by Layotto. The SDK is located in the sdk directory. Users can directly call the APIs provided by Layotto through the corresponding SDK.

Besides the SDK,you can also call Layotto server directly using grpc,which makes it easy for different language to interact with Layotto.