59
57

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

redis-pyの使い方 辞書とか

Last updated at Posted at 2013-02-17
pip install redis

pythonでは以下のように

import redis
r = redis.Redis(host='localhost', port=6379, db=0)

#全て消す
r.flushall()

#hashを保存
#key_nameにdictをsetできる
r.hmset(key_name, dict)

#1個ずつ保存の場合
r.hset(key_name, field_name, val)

#hashを取得
r.hgetall(key_name)

#hashのkeyのみ
r.hkeys(key_name)

#hashのvalueのみ
r.hvals(key_name)

#指定したfieldのみ
r.hget(key_name, field_name)

#指定したkeyとfieldをインクリメント
r.hincrby(key_name, field_name, value)

#fieldの存在チェック
r.hexists(key_name,field_name)

#keyの一覧
r.keys()

対話型とほぼ同じインターフェースで使えるのが良いですね。
listとかもドキュメントみながらさわればすぐ覚えられそう

59
57
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
59
57

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?