So turns out you return nil values for fields that don’t exist in the hash.
https://github.com/gomodule/redigo/issues/396
Surprisingly, you return these nil fields if any hash in the request has them. I.e. if I ONLY get one result back, you don’t return nil values:
[]interface {}{[]interface {}{"_t", []uint8{0x31, 0x35, 0x34, 0x37, 0x37, 0x35, 0x34, 0x34, 0x39, 0x32}, “vin”, []uint8{0x31, 0x68, 0x66, 0x73, 0x63, 0x34, 0x37, 0x30, 0x78, 0x35, 0x61, 0x34, 0x31, 0x31, 0x32, 0x33, 0x33}, “created”, []uint8{0x32, 0x30, 0x31, 0x39, 0x2d, 0x30, 0x31, 0x2d, 0x31, 0x37, 0x20, 0x31, 0x39, 0x3a, 0x34, 0x38, 0x3a, 0x31, 0x32}, “url”, []uint8{0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x69, 0x6d, 0x6f, 0x74, 0x6f, 0x72, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x6f, 0x72, 0x6c, 0x61, 0x6e, 0x64, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x2e, 0x61, 0x73, 0x70, 0x3f, 0x70, 0x61, 0x67, 0x65, 0x3d, 0x78, 0x50, 0x72, 0x65, 0x4f, 0x77, 0x6e, 0x65, 0x64, 0x49, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x26, 0x69, 0x64, 0x3d, 0x36, 0x35, 0x38, 0x31, 0x38, 0x32, 0x31, 0x26, 0x70, 0x3d, 0x33, 0x30, 0x26, 0x73, 0x3d, 0x59, 0x65, 0x61, 0x72, 0x26, 0x64, 0x3d, 0x44, 0x26, 0x76, 0x74, 0x3d, 0x6d, 0x6f, 0x74, 0x6f, 0x72, 0x63, 0x79, 0x63, 0x6c, 0x65, 0x25, 0x32, 0x30, 0x25, 0x32, 0x46, 0x25, 0x32, 0x30, 0x73, 0x63, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x26, 0x66, 0x72, 0x3d, 0x78, 0x50, 0x72, 0x65, 0x4f, 0x77, 0x6e, 0x65, 0x64, 0x49, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79}, “year”, []uint8{0x32, 0x30, 0x30, 0x35}, “geo”, []uint8{0x2d, 0x38, 0x31, 0x2e, 0x33, 0x37, 0x39, 0x32, 0x33, 0x36, 0x35, 0x20, 0x32, 0x38, 0x2e, 0x35, 0x33, 0x38, 0x33, 0x33, 0x35, 0x35}, “st”, []uint8{0x46, 0x4c}, “ctitle”, []uint8{0x6c}, “location”, []uint8{0x4f, 0x72, 0x6c, 0x61, 0x6e, 0x64, 0x6f, 0x2c, 0x20, 0x46, 0x4c}, “tags”, []uint8{0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x3a, 0x74, 0x3a, 0x64, 0x65, 0x61, 0x6c, 0x65, 0x72, 0x2c, 0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x3a, 0x74, 0x3a, 0x75, 0x73, 0x65, 0x64, 0x2c, 0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x3a, 0x74, 0x3a, 0x68, 0x61, 0x73, 0x76, 0x69, 0x6e, 0x2c, 0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x3a, 0x74, 0x3a, 0x67, 0x6f, 0x6c, 0x64, 0x77, 0x69, 0x6e, 0x67, 0x2c, 0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x3a, 0x74, 0x3a, 0x68, 0x6f, 0x6e, 0x64, 0x61, 0x2c, 0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x2c, 0x66, 0x3a, 0x69, 0x6d, 0x6f, 0x74, 0x6f, 0x72, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x75, 0x73, 0x65, 0x64, 0x2c, 0x63, 0x66, 0x3a, 0x64, 0x3a, 0x31, 0x30, 0x39, 0x2c, 0x63, 0x66, 0x3a, 0x6d, 0x3a, 0x64, 0x73, 0x2c, 0x46, 0x4c}, “mpid”, []uint8{0x63, 0x66, 0x3a, 0x6d, 0x3a, 0x64, 0x73}, “title”, []uint8{0x32, 0x30, 0x30, 0x35, 0x20, 0x48, 0x6f, 0x6e, 0x64, 0x61, 0xc2, 0xae, 0x20, 0x47, 0x6f, 0x6c, 0x64, 0x20, 0x57, 0x69, 0x6e, 0x67, 0x20, 0x54, 0x72, 0x69, 0x6b, 0x65}, “feed”, []uint8{0x66, 0x3a, 0x69, 0x6d, 0x6f, 0x74, 0x6f, 0x72, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x75, 0x73, 0x65, 0x64}, “mileage”, []uint8{0x34, 0x30, 0x30, 0x30, 0x30}, “guid”, []uint8{0x36, 0x35, 0x38, 0x31, 0x38, 0x32, 0x31}, “did”, []uint8{0x63, 0x66, 0x3a, 0x64, 0x3a, 0x31, 0x30, 0x39}}}
But if the response contained multiple documents, you fill-in the values as nil for all documents that didn’t have them.
This is the same document when it’s the second result in the response. It doesn’t have an imgy field, yet you return one. This also incurs performance penalty - although probably negligible.
[]interface {}{[]interface {}{"_t", []uint8{0x31, 0x35, 0x34, 0x37, 0x37, 0x35, 0x34, 0x34, 0x39, 0x32}, “imgy”, interface {}(nil), “ctitle”, []uint8{0x6c}, “location”, []uint8{0x4f, 0x72, 0x6c, 0x61, 0x6e, 0x64, 0x6f, 0x2c, 0x20, 0x46, 0x4c}, “ph”, interface {}(nil), “mpid”, []uint8{0x63, 0x66, 0x3a, 0x6d, 0x3a, 0x64, 0x73}, “tags”, []uint8{0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x3a, 0x74, 0x3a, 0x64, 0x65, 0x61, 0x6c, 0x65, 0x72, 0x2c, 0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x3a, 0x74, 0x3a, 0x75, 0x73, 0x65, 0x64, 0x2c, 0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x3a, 0x74, 0x3a, 0x68, 0x61, 0x73, 0x76, 0x69, 0x6e, 0x2c, 0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x3a, 0x74, 0x3a, 0x67, 0x6f, 0x6c, 0x64, 0x77, 0x69, 0x6e, 0x67, 0x2c, 0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x3a, 0x74, 0x3a, 0x68, 0x6f, 0x6e, 0x64, 0x61, 0x2c, 0x77, 0x3a, 0x63, 0x6f, 0x75, 0x63, 0x68, 0x72, 0x69, 0x64, 0x65, 0x2c, 0x66, 0x3a, 0x69, 0x6d, 0x6f, 0x74, 0x6f, 0x72, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x75, 0x73, 0x65, 0x64, 0x2c, 0x63, 0x66, 0x3a, 0x64, 0x3a, 0x31, 0x30, 0x39, 0x2c, 0x63, 0x66, 0x3a, 0x6d, 0x3a, 0x64, 0x73, 0x2c, 0x46, 0x4c}, “currency”, interface {}(nil), “created”, []uint8{0x32, 0x30, 0x31, 0x39, 0x2d, 0x30, 0x31, 0x2d, 0x31, 0x37, 0x20, 0x31, 0x39, 0x3a, 0x34, 0x38, 0x3a, 0x31, 0x32}, “imgx”, interface {}(nil), “url”, []uint8{0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x69, 0x6d, 0x6f, 0x74, 0x6f, 0x72, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x6f, 0x72, 0x6c, 0x61, 0x6e, 0x64, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x2e, 0x61, 0x73, 0x70, 0x3f, 0x70, 0x61, 0x67, 0x65, 0x3d, 0x78, 0x50, 0x72, 0x65, 0x4f, 0x77, 0x6e, 0x65, 0x64, 0x49, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x26, 0x69, 0x64, 0x3d, 0x36, 0x35, 0x38, 0x31, 0x38, 0x32, 0x31, 0x26, 0x70, 0x3d, 0x33, 0x30, 0x26, 0x73, 0x3d, 0x59, 0x65, 0x61, 0x72, 0x26, 0x64, 0x3d, 0x44, 0x26, 0x76, 0x74, 0x3d, 0x6d, 0x6f, 0x74, 0x6f, 0x72, 0x63, 0x79, 0x63, 0x6c, 0x65, 0x25, 0x32, 0x30, 0x25, 0x32, 0x46, 0x25, 0x32, 0x30, 0x73, 0x63, 0x6f, 0x6f, 0x74, 0x65, 0x72, 0x26, 0x66, 0x72, 0x3d, 0x78, 0x50, 0x72, 0x65, 0x4f, 0x77, 0x6e, 0x65, 0x64, 0x49, 0x6e, 0x76, 0x65, 0x6e, 0x74, 0x6f, 0x72, 0x79}, “title”, []uint8{0x32, 0x30, 0x30, 0x35, 0x20, 0x48, 0x6f, 0x6e, 0x64, 0x61, 0xc2, 0xae, 0x20, 0x47, 0x6f, 0x6c, 0x64, 0x20, 0x57, 0x69, 0x6e, 0x67, 0x20, 0x54, 0x72, 0x69, 0x6b, 0x65}, “imgurl”, interface {}(nil), “feed”, []uint8{0x66, 0x3a, 0x69, 0x6d, 0x6f, 0x74, 0x6f, 0x72, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x75, 0x73, 0x65, 0x64}, “mileage”, []uint8{0x34, 0x30, 0x30, 0x30, 0x30}, “price”, interface {}(nil), “imgsmallx”, interface {}(nil), “imgurlsmall”, interface {}(nil), “imgsmally”, interface {}(nil), “st”, []uint8{0x46, 0x4c}, “geo”, []uint8{0x2d, 0x38, 0x31, 0x2e, 0x33, 0x37, 0x39, 0x32, 0x33, 0x36, 0x35, 0x20, 0x32, 0x38, 0x2e, 0x35, 0x33, 0x38, 0x33, 0x33, 0x35, 0x35}, “vin”, []uint8{0x31, 0x68, 0x66, 0x73, 0x63, 0x34, 0x37, 0x30, 0x78, 0x35, 0x61, 0x34, 0x31, 0x31, 0x32, 0x33, 0x33}, “year”, []uint8{0x32, 0x30, 0x30, 0x35}, “guid”, []uint8{0x36, 0x35, 0x38, 0x31, 0x38, 0x32, 0x31}, “did”, []uint8{0x63, 0x66, 0x3a, 0x64, 0x3a, 0x31, 0x30, 0x39}}}
Michael