CentOS 7
Sponsored Link

Redis : 基本操作 #42016/07/21

 
専用のクライアントプログラム「redis-cli」を利用した場合の Redis の基本操作です。
以下の例の他にも非常に多くのコマンドが用意されています。詳細は本家サイトを参照ください。
⇒ http://redis.io/commands
[1] 基本的なハッシュ操作の例です。
[root@dlp ~]#
redis-cli -a password
# ハッシュの指定フィールドに値を追加する
127.0.0.1:6379> hset hash01 field01 value01 
(integer) 1

# ハッシュの指定フィールドの値を返す
127.0.0.1:6379> hget hash01 field01 
"value01"

# ハッシュの複数フィールドに追加する
127.0.0.1:6379> hmset hash01 field02 value02 field03 value03 
OK

# ハッシュの複数フィールドの値を返す
127.0.0.1:6379> hmget hash01 field01 field02 field03 
1) "value01"
2) "value02"
3) "value03"

# ハッシュのフィールドを全て返す
127.0.0.1:6379> hkeys hash01 
1) "field01"
2) "field02"
3) "field03"

# ハッシュのフィールドの値を全て返す
127.0.0.1:6379> hvals hash01 
1) "value01"
2) "value02"
3) "value03"

# ハッシュのフィールドと値を全て返す
127.0.0.1:6379> hgetall hash01 
1) "field01"
2) "value01"
3) "field02"
4) "value02"
5) "field03"
6) "value03"

# ハッシュの指定フィールドの値を指定数プラスする
127.0.0.1:6379> hincrby hash01 field04 100 
(integer) 101

# ハッシュの指定フィールドが存在するか確認する
127.0.0.1:6379> hexists hash01 field01 
(integer) 1

# ハッシュのフィールド数を返す
127.0.0.1:6379> hlen hash01 
(integer) 4

# ハッシュの指定フィールドを削除する
127.0.0.1:6379> hdel hash01 field04 
(integer) 1
関連コンテンツ