SpringBoot整合Redis

來源:互聯網
上載者:User

標籤:import   color   arc   frame   特性   lease   有序   contex   cto   

Redis介紹

Redis是一個完全開源免費的, 是一個高效能的key-value資料庫。

Redis 與其他 key - value 緩衝產品有以下三個特點:

  • Redis支援資料的持久化,可以將記憶體中的資料儲存在磁碟中,重啟的時候可以再次載入進行使用。

  • Redis不僅僅支援簡單的key-value類型的資料,同時還提供結構list,set,zset,hash等資料的儲存。

  • Redis支援資料的備份,即master-slave模式的資料備份。

Redis優勢
  • 效能極高 – Redis能讀的速度是110000次/s,寫的速度是81000次/s 。

  • 豐富的資料類型 – Redis支援二進位案例的 Strings, Lists, Hashes, Sets 及 Ordered Sets 資料類型操作。

  • 原子 – Redis的所有操作都是原子性的,同時Redis還支援對幾個操作全並後的原子性執行。

  • 豐富的特性 – Redis還支援 publish/subscribe, 通知, key 到期等等特性。

Redis支援五種資料類型:

string(字串)、list(列表)、set(集合)、hash(雜湊)、zset(sorted set有序集合)

安裝Redis

redis沒有官方版的windows版本,但是GitHub有開源組織維護的版本
redis windows64位版本
啟動命令redis-server.exe redis.windows.conf

maven依賴
1 <!--redis-->2 <dependency>3     <groupId>org.springframework.boot</groupId>4     <artifactId>spring-boot-starter-redis</artifactId>5 </dependency>6 <dependency>7     <groupId>org.springframework.boot</groupId>8     <artifactId>spring-boot-starter-data-redis</artifactId>9 </dependency>
properties配置
1 #連接埠號碼2 server.port=80663 4 #redis配置5 spring.redis.database=16 spring.redis.host=localhost7 spring.redis.port=63798 spring.redis.timeout=3000
單元測試類測試存取
 1 package com.example.inchlifc; 2  3 import org.junit.Test; 4 import org.junit.runner.RunWith; 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.boot.test.context.SpringBootTest; 7 import org.springframework.data.redis.core.StringRedisTemplate; 8 import org.springframework.test.context.junit4.SpringRunner; 9 10 @RunWith(SpringRunner.class)11 @SpringBootTest12 public class InchlifcApplicationTests {13 14    @Autowired15    StringRedisTemplate stringRedisTemplate;16    @Test17    public void contextLoads() {18       //儲存字串19       stringRedisTemplate.opsForValue().set("redisTest", "小小漁夫");20    }21 22 }
測試結果

SpringBoot整合Redis

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.