Redis keyに設定されているハッシュ値を削除する

Redisで、keyに設定されているハッシュ値を削除する手順を記述してます。「hdel」を使用します。ここでは、実際に実行した結果を掲載してます。
環境
- OS CentOS Stream release 9
- Redis 7.0.5
手順
keyに設定されているハッシュ値を削除するには、「hdel」を使用します。
hdel キー名 フィールド名 フィールド名 . . .
実際に、指定して削除してみます。
127.0.0.1:6379> hset key1 hash1 "abc"
(integer) 1
127.0.0.1:6379> hset key1 hash2 "de"
(integer) 1
127.0.0.1:6379> hdel key1 hash3
(integer) 1
127.0.0.1:6379> hgetall key1
1) "hash1"
2) "abc"
3) "hash2"
4) "de"
削除されていることが確認できます。
一度に複数削除することも可能です。
127.0.0.1:6379> hdel key1 hash1 hash2
(integer) 2
127.0.0.1:6379> hgetall key1
(empty array)
-
前の記事
mac 正規表現でテキストのファイルの最後尾に文字列を追加する 2023.12.13
-
次の記事
kotlin Listのインデックス番号の範囲を指定する 2023.12.14
コメントを書く