Use State API to manage state
What is State API
Your application can use the same State API to operate different databases (or a certain storage system) to add, delete, modify and query the data of the Key/Value model.
API supports batch CRUD operations and supports the declaration of requirements for concurrency safety and data consistency. Layotto will deal with complex concurrency safety and data consistency issues for you.
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
step 1. Deploy Redis and Layotto
with Docker Compose
You can start Redis and Layotto with docker-compose
cd docker/layotto-redis
# Start redis and layotto with docker-compose
docker-compose up -d
Compile locally (not for Windows)
You can run Redis with Docker, then compile and run Layotto locally.
[!TIP|label: Not for Windows users] Layotto fails to compile under Windows. Windows users are recommended to deploy using docker-compose
step 1.1. Run Redis with Docker
- Get the latest version of Redis docker image
Here we pull the latest version of the official image:
docker pull redis:latest
- View the local mirror
Use the following command to check if redis is installed:
docker images
- 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.
step 1.2. Compile and Run Layotto
After downloading the project code to the local, change the code directory:
# change directory to ${your project path}/cmd/layotto
cd cmd/layotto
and then build layotto:
go build -o layotto
The layotto file will be generated in the directory, run it:
./layotto start -c ../../configs/config_redis.json