redis Connecting to redis using Python Adding fields to a Hash


Example

There are two main functions in Redis (HSET and HMSET) for adding fields to a hash key. Both functions are available in redis-py.

Using HSET:

import redis

r = redis.StrictRedis(host='myserver', port=6379, db=0)
r.hset('my_key', 'field0', 'value0')

Using HMSET:

import redis

r = redis.StrictRedis(host='myserver', port=6379, db=0)
r.hmset('my_key', {'field0': 'value0', 'field1':'value1', 'field2':'value2'}