English | 中文
- Rust
- MySQL 5.7
- Execute
init.sql
to create tables. - Set environment variable
DATABASE_URL
andJWT_SECRET
in.env
. - Execute
run.sh
.
- /user/register
- /user/login
JWT should be provided in header.
Authorization: Bearer <JWT>
- /book/create
- /book/search
- /book/update
- /book/delete
- Add redis with feature
tokio-comp
to Cargo.toml
async
is necessary, because if you don't useasync
, the system thread will block when the command is executing, and it will not handle other tasks.
- Add
redis::RedisError
in src/error.rs
#[error("redis_error: {0}")]
Redis(#[from] redis::RedisError),
With
#[from]
, thiserror will generateimpl From<redis::RedisError> for CustomError
automatically, and you can return error with?
or.map_err(Into::into)?
when the return type isCustomResult<T>
.
Without#[from]
, you need to convert error by yourself.map_err(|e| CustomError::Redis(e))
or.map_err(CustomError::Redis)
- Read code in redis/examples.
- Write your cache code.
- Add Global-404-handler in
src/bin/server.rs
.