使用redis進行快取

2022-07-07 00:12:13 字數 675 閱讀 4633

**/

@enablecaching //開啟快取

@configuration //配置類

public class redisconfig extends cachingconfigurersupport

@bean

public cachemanager cachemanager(redisconnectionfactory factory)

}

第二步,在方法上面加入快取註解,

@cacheable(key = "", value = "")

就可以把方法的返回值加入快取。

在linux下使用命令開啟redis服務,要注意命令的後面需指定配置檔案如:

./redis-server /etc/redis.conf

在配置檔案中配置redis

#spring.redis.host=192.168.5.129

#spring.redis.port=6379

#spring.redis.database= 0

#spring.redis.timeout=1800000

連線redis的坑:

1.未關閉linux防火牆

2.配置檔案有問題

需要注釋掉127.0.0.1

如果出現:

使用Redis進行簡單的資料快取

引入spring data redis包 jedis connection pool包 bean id redisconnection class org.springframework.data.redis.connection.jedis.jedisconnectionfactory prope...

redis快取使用

compile group org.springframework.boot name spring boot starter data redis version 2.3.2.release spring 主要引數 redis host localhost port 6379 passport 預...

快取Redis使用

在 redis 中有五種資料型別 redis 內部使用乙個 redisobject 物件來表示所有的 key 和 value。redis 記憶體淘汰指的是使用者儲存的一些鍵被可以被 redis 主動地從例項中刪除,從而產生讀 miss 的情況,那麼 redis 為什麼要有這種功能?這就是我們需要 的...