redis全体削除、hash全体削除、一括削除、単一削除、正則削除

810 ワード

redisのhashデータ構造の削除:
pool = redis.ConnectionPool(host='127.0.0.1',port=6381,db=0,decode_responses=True)
r = redis.Redis(connection_pool=pool)
pool = redis.ConnectionPool(host='127.0.0.1',port=6381,decode_responses=True)
r = redis.Redis(connection_pool=pool)
r = redis.Redis(host='127.0.0.1',port=6381,db=0,decode_responses=True)

以上の3つのデータベースへの接続方法はすべて有効で、主に後のdecode_です.responsesパラメータは、バイナリ書き込みを省くことができます.
 
データベース全体の削除:
r.fushall()
hash全体の大きな辞書を一括削除するには、次の手順に従います.
r.delete(*r.keys('^test')#はtestで始まるhashの大きな辞書を削除することを表します.
r.delete(key 1,key 2)#は、key 1辞書とkey 2辞書の削除を表す
hash辞書全体の削除:
r.delete(dict_name)
特定のhash辞書の複数のキーを一括削除します.
r.hdel(dict_name,key1)