getZSetFromDB fetches and deserializes FZSet from the database. Returns a pointer to the FZSet and error, if any. If the key doesn't exist, both the pointer and the error will be nil. In case of deserialization errors, returns nil and the error.
(key []byte)
| 1066 | // If the key doesn't exist, both the pointer and the error will be nil. |
| 1067 | // In case of deserialization errors, returns nil and the error. |
| 1068 | func (zs *ZSetStructure) getZSetFromDB(key []byte) (*FZSet, error) { |
| 1069 | dbData, err := zs.db.Get(key) |
| 1070 | |
| 1071 | // If key is not found, return nil for both; otherwise return the error. |
| 1072 | if err != nil { |
| 1073 | |
| 1074 | return nil, err |
| 1075 | } |
| 1076 | dec := encoding.NewMessagePackDecoder(dbData) |
| 1077 | // Deserialize the data. |
| 1078 | var zSetValue FZSet |
| 1079 | if err = dec.Decode(&zSetValue); err != nil { |
| 1080 | return nil, err |
| 1081 | } |
| 1082 | |
| 1083 | // return a pointer to the deserialized FZSet, nil for the error |
| 1084 | return &zSetValue, nil |
| 1085 | } |
| 1086 | |
| 1087 | // checkKey function that accepts a string parameter key |
| 1088 | // and returns error if key is empty. |