python操作redis-hash
#!/usr/bin/python #!coding: utf-8 import redis if __name__=="__main__": try: conn=redis.StrictRedis(host='192.168.80.128',port=6379,db=0) print(conn.ping()) conn.hset('persons:001','name','jiangle') #让hash表persons:001的name关键字(key)关联到一个值‘jiangle’ name=conn.hget('persons:001','name') print(name) #取出hash表persons:001的name关键字所关联的值 print(conn.hgetall('persons:001')) #取得hash表persons:001中所有的键值 print(conn.hexists('persons:001','name')) #判断hash表persons:001是否存在name这个键 print(conn.hget('persons:001','age')) conn.hincrby('persons:001','age',2) print(conn.hget('persons:001','age')) #自增 conn.hdel('persons:001','age') print(conn.hkeys('persons:001')) #删除键 except Exception as err: print(err)