Redis基本資料及操作

2021-08-22 00:27:17 字數 3775 閱讀 4290

set

>set name zhangsan

ok>get name

zhangsan

自增increase-incr

>incr key1

(integer) 1

>incr key1

(integer) 2

自減decrease-decr

>decr key1

(integer) 1

檢視-keys

>keys *

1) "name"

2) "key1"

刪除-del

>del key1

(integer) 1

>keys *

1) "name"

hset

>hset hash1 field1 1

(integer) 1

>hget hash1 field1

"1">hset hash1 field2 2

(integer) 1

>hset hash1 field3 a

(integer) 1

檢視(key)-hkeys

>hkeys hash1

1) "field1"

2) "field2"

3) "field3"

檢視(key-value)-hgetall

>hgetall hash1

1) "field1"

2) "1"

1) "field2"

2) "2"

1) "field3"

2) "a"

刪除-hdel

>hdel hash1 field3

(integer) 1

>hkeys hash1

1) "field1"

2) "field2"

lpush & rpush

>lpush list1 a b c d

(integer) 4

>lrange list1 0 -1

1) "d"

2) "c"

3) "b"

4) "a"

>rpush list1 1 2 3 4

(integer) 8

>lrange list1 0 -1

1) "d"

2) "c"

3) "b"

4) "a"

5) "1"

6) "2"

7) "3"

8) "4"

刪除-lpop&rpop

>lpop list1 

"d">lrange list1 0 -1

1) "c"

2) "b"

3) "a"

4) "1"

5) "2"

6) "3"

7) "4"

>rpop list1

"4">lrange list1 0 -1

1) "c"

2) "b"

3) "a"

4) "1"

5) "2"

6) "3"

sadd

>sadd set1 a b c c c d

(integer) 4

檢視-smembers

>smembers set1

1) "b"

2) "c"

3) "d"

4) "a"

刪除-srem

>srem set1 a

(integer) 1

>smembers set1

1) "b"

2) "c"

3) "d"

差集-sdiff

>sadd seta a b c d e

(integer) 5

>sadd setb c d e f g

(integer) 5

>sdiff seta setb

1) "a"

2) "b"

>sdiff setb seta

1) "f"

2) "g"

交集-sinter

>sinter seta setb

1) "d"

2) "e"

3) "c"

並集-sunion

>sunion seta setb

1) "d"

2) "g"

3) "b"

4) "f"

5) "a"

6) "e"

7) "c"

有序set (score-value)

>zadd zset1 1 a 3 b 2 c 5 d

(integer) 4

>zrange zset1 0 -1

1) "a"

2) "c"

3) "b"

4) "d"

刪除-zrem

>zrem zset1 a

(integer) 1

>zrange zset 0 -1

1) "c"

2) "b"

3) "d"

檢視-降序-zrevrange

>zrevrange zset1 0 -1

1) "d"

2) "b"

3) "c"

檢視score&value - withscore

>zrange zset1 0 -1 withscores

1) "c"

2) "2"

3) "b"

4) "3"

5) "d"

6) "5"

>zrevrange zset1 0 -1 withscores

1) "d"

2) "5"

3) "b"

4) "3"

5) "c"

6) "2"

設定過期時間-expire

>set name hello

(integer) 1

>expire name 20

(integer) 1

檢視過期時間-ttl   (注:存在的顯示剩餘時間,不存在的為-2,持久的為-1)

>ttl name

(integer) 10

>ttl name

(integer) -2

>ttl seta

(integer) -1

清除過期時間-persist

>set name zhangsan

(integer) 1

>expire zhangsan 100

(integer) 1

>ttl zhangsan

(integer) 77

>persist zhangsan

(integer) 1

redis的基本資料型別及基本操作 一

string型別是二進位制安全的,意思是redis可以包含任何資料,例如 序列化物件等等,下面是string型別的定義 其中buf用於存貯string的字元,free記錄剩餘可用的位元組數。如果只是redis只是使用string型別,那麼就可以認為是持久化特性的memcathe。下面的 介紹stri...

redis 基本資料型別基本操作

string string hash hashmap list linkedlist set hashset sorted set tree set 設定數值資料減少指定範圍的值 設定資料的過期時間 psetex key milliseconds value 設定指定欄位的數值資料增加指定範圍的值 ...

Redis基本資料型別及命令

redis的資料結構 字串 string 字串列表 list 字串集合 set 有序字串集合 sorted set 雜湊 hash 常用命令 設定值set key value 先獲取再設定 getset key value 獲取值get key 刪除值del key 增減incr key 將制定ke...