Redis keyに設定されているハッシュ値の値のみを全て取得する

Redisで、keyに設定されているハッシュ値の値のみを全て取得する手順を記述してます。「hvals」にキー名を指定することで可能です。ここでは、実際に実行した結果を掲載してます。
環境
- OS CentOS Stream release 9
- Redis 7.0.5
手順
keyに設定されているハッシュ値の値のみを全て取得するには、「hvals」を使用します。
hvals キー名
実際に、いくつか作成して値のみを取得してみます。
127.0.0.1:6379> hexists key1 hash1
(integer) 1
127.0.0.1:6379> hexists key1 hash2
(integer) 1
127.0.0.1:6379> hexists key1 hash3
(integer) 0
127.0.0.1:6379> hset key1 hash3 "fg"
(integer) 1
127.0.0.1:6379> hvals key1
1) "abc"
2) "de"
3) "fg"
取得できていることが確認できます。
ハッシュ値がない場合は、空が返ります。
127.0.0.1:6379> set kye2 "v"
OK
127.0.0.1:6379> hvals key2
(empty array)
127.0.0.1:6379> hvals nokey
(empty array)
フィールド値のみを取得
値のみを取得する場合は、「hkeys」を使用します。
127.0.0.1:6379> hkeys key1
1) "hash1"
2) "hash2"
3) "hash3"
両方取得
両方とも取得する場合は、「hgetall」を使用します。
127.0.0.1:6379> hgetall key1
1) "hash1"
2) "abc"
3) "hash2"
4) "de"
5) "hash3"
6) "fg"
-
前の記事
Google ドライブ 新規のフォームを作成するショートカットキー 2023.12.05
-
次の記事
MariaDB 日付から月を英語に変換する 2023.12.05
コメントを書く