redis刪除指定key中的指定元素的方法

2021-09-10 02:37:26 字數 2031 閱讀 5961

127.0

.0.1

:6379

> keys *1)

"_kombu.binding.celery.pidbox"2)

"_kombu.binding.celery"3)

"_kombu.binding.celeryev"4)

"key"5)

"db_number"6)

"myhash"7)

"key1"8)

"data_string"9)

"data_list"10)

"set1"

127.0.0.1:6379> del key

(integer) 1

127.0.0.1:6379> keys *

1) "_kombu.binding.celery.pidbox"

2) "_kombu.binding.celery"

3) "_kombu.binding.celeryev"

4) "db_number"

5) "myhash"

6) "key1"

7) "data_string"

8) "data_list"

9) "set1"

127.0

.0.1

:6379

> lrange data_list 0

10顯示指定key的資料1)

"test_function"2)

"rabbitmq"3)

"haha"4)

"redis"

127.0

.0.1

:6379

> lrem data_list 0 test_function#刪除值為test_function的字串

(integer)

1顯示指定key的資料

127.0

.0.1

:6379

> lrange data_list 0

10顯示指定key的資料1)

"rabbitmq"2)

"haha"3)

"redis"

127.0

.0.1

:6379

>

hgetall myhash1)

"field1"2)

"hello"3)

"field2"4)

"world"

127.0

.0.1

:6379

>

hdel myhash field1 hello

(integer)

1127.0

.0.1

:6379

>

hgetall myhash1)

"field2"2)

"world"

string型別的key在設定資料的時候,就會覆蓋之前的資料,所以等效於刪除原有的資料了.

127.0

.0.1

:6379

>

set data_string republic

ok127.0

.0.1

:6379

>

get data_string

"republic"

127.0

.0.1

:6379

>

127.0

.0.1

:6379

>

smembers set11)

"mongodb"2)

"redis"3)

127.0

.0.1

:6379

>

(integer)

1127.0

.0.1

:6379

>

smembers set11)

"mongodb"2)

"redis"

redis批量刪除指定的key

批量刪除key redis 中有刪除單個 key 的指令 del,可以借助 linux 的 xargs 指令來完成這個動作 redis cli keys xargs redis cli del 如果redis cli沒有設定成系統變數,需要指定redis cli的完整路徑 如 opt redis r...

redis集群批量刪除指定的key

工作中遇到乙個問題,redis中儲存了大量的key,而且沒有設定時效,其中很大一部分後來都沒用了,導致redis體積龐大,查詢緩慢。伺服器版本為windows,網上搜尋到很多批量刪除的方法都是linux下的,幾番尋找,終於找到了在windows下批量刪除超大量key的方法。首先貼一下linux下的方...

redis中批量刪除key

1 刪除所有的key,可以使用redis自身的命令 flushdb 刪除當前資料庫中的所有key flushall 刪除所有資料庫中的key 2 使用linux中的xargs來刪除所有的key redis cli keys xargs redis cli del 3 刪除包含有某些關鍵字的key r...