Expand description
§sa-token-storage-redis
Redis存储实现
适用于:
- 分布式部署
- 需要数据持久化
- 高性能要求的场景
§使用方式
§方式 1: 使用 Redis URL
ⓘ
use sa_token_storage_redis::RedisStorage;
// 无密码
let storage = RedisStorage::new("redis://localhost:6379/0", "sa-token:").await?;
// 有密码
let storage = RedisStorage::new("redis://:password@localhost:6379/0", "sa-token:").await?;§方式 2: 使用配置结构体
ⓘ
use sa_token_storage_redis::{RedisStorage, RedisConfig};
let config = RedisConfig {
host: "localhost".to_string(),
port: 6379,
password: Some("your-password".to_string()),
database: 0,
pool_size: 10,
};
let storage = RedisStorage::from_config(config, "sa-token:").await?;Structs§
- Redis
Config - Redis 配置
- Redis
Storage - Redis存储实现
- Redis
Storage Builder - Redis 存储构建器