---
# System prepended metadata

title: Redis
tags: [redis]

---

# Redis

###### tags: `redis`

## 安裝 server

### macOS

```shell
$ brew install redis
```

配置文件在 `/usr/local/etc/redis.conf`。

#### 啟動

```shell
$ brew services start redis
```

#### 不需要後台服務，則可以直接運行：

```shell
$ redis-server /usr/local/etc/redis.conf
```

#### 測試 Redis 伺服器是否正在運行

```shell
$ redis-cli ping
```

若出現`PONG`則表示正在運行。

#### 卸載

```shell
$ brew uninstall redis ; rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
```

### Windows

載點：https://github.com/microsoftarchive/redis/releases

![](https://i.imgur.com/gOcR5ap.png)

## 安裝 GUI client

載點：

* https://github.com/uglide/RedisDesktopManager/releases/download/0.8.8/redis-desktop-manager-0.8.8.384.exe
* https://rdbtools.com/docs/install/windows/

## 在 Spring Boot 中使用

### `/pom.xml`

```xml
<!-- Redis -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

<!-- Spring Boot Cache -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-cache</artifactId>
</dependency>

<!-- Spring Session -->
<dependency>
	<groupId>org.springframework.session</groupId>
	<artifactId>spring-session-data-redis</artifactId>
</dependency>
```

### `/src/main/resources/application.properties`

```
spring.cache.type=redis
spring.redis.host=localhost
spring.redis.lettuce.pool.max-active=8
spring.redis.lettuce.pool.max-idle=8
spring.redis.lettuce.pool.min-idle=0
spring.redis.password=
spring.redis.port=6379
spring.redis.ssl=false
spring.redis.url=
spring.redis.username=
```

### `/src/main/java/{package}/Application.java`

```java
@EnableRedisHttpSession
@SpringBootApplication
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}
```
