1. 程式人生 > 實用技巧 >Redis學習總結

Redis學習總結

Redis學習小結

在7月中旬,我成功入職實習,通過進入公司,認識到了個人與企業巨大的差距,首先就是對於中介軟體的使用,ElasticSearch、Redis、Kafka等等,都是聽過卻從未使用過的,然而在任務下達之後,激勵了學習動力,首先就是Redis。

網站

Redis官網:https://redis.io/

Redis的中文文件網站:http://www.redis.cn/

Redis是什麼(轉):https://www.cnblogs.com/powertoolsteam/p/redis.html

Redis的全部命令:http://www.redis.cn/commands.html

關於Redis

Redis(Remote Dictionary Server ):遠端字典服務,C語言編寫,屬於NoSQL,key-value資料庫,支援分散式(重點),常用作快取。

安裝:前往官網下載,注意對應系統,具體內容詳見:https://www.runoob.com/redis/redis-install.html

Redis資料結構

Redis支援以下5種資料結構

1)字串(strings)
2)字串列表(lists)
3)字串集合(sets)
4)有序字串集合(sorted sets)
5)雜湊(hashes)

不過在文件中查詢命令時可以發現分的非常細緻

所以當需要查詢命令的時候不妨分類查詢或是快速搜尋

String

字串型別是Redis用的最多的地方,是所有儲存系統最基礎的型別,因此入門就必須掌握它。

以下是String中的命令(參考視訊:https://www.bilibili.com/video/BV1S54y1R7SB

1)get、set、EXISTS、APPEND、STRLEN

2)incr、decr、INCRBY、DECRBY

3)GETRANGE、SETRANGE

4)setex、setnx

5)mset(可以設定物件)、mget、getset

 mset

mget

getset

List

其他還有很多型別,就不一一列舉了,詳情參考文件--命令

Springboot配置Redis

Springboot作為目前Java開發主流框架,自然可以支援Redis。

首先在 pom.xml 中引入依賴

<dependency>
            <groupId>
org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>${redis-version}</version> </dependency>

然後就是配置檔案,這裡我使用的是 properties檔案

# Redis資料庫索引(預設為0)
spring.redis.database=0
# Redis伺服器地址
spring.redis.host=127.0.0.1
# Redis伺服器連線埠
spring.redis.port=6379
# Redis伺服器連線密碼(預設為空)
spring.redis.password=
# 連線池最大連線數(使用負值表示沒有限制)
spring.redis.jedis.pool.max-active=20
# 連線池最大阻塞等待時間(使用負值表示沒有限制)
spring.redis.jedis.pool.max-wait=-1
# 連線池中的最大空閒連線
spring.redis.jedis.pool.max-idle=10
# 連線池中的最小空閒連線
spring.redis.jedis.pool.min-idle=0
# 連線超時時間(毫秒)
spring.redis.timeout=1000

配置就OK了,如何簡單使用:https://www.cnblogs.com/Zs-book1/p/11451689.html