2017-06-30 21:10:25 +05:30
|
|
|
package redis
|
2017-06-19 04:50:38 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"compress/zlib"
|
2017-06-30 21:10:25 +05:30
|
|
|
"io"
|
|
|
|
"strings"
|
2017-06-19 04:50:38 +05:30
|
|
|
)
|
|
|
|
|
2017-06-30 21:10:25 +05:30
|
|
|
func buildKey(username string) string {
|
|
|
|
return "username:" + strings.ToLower(username)
|
|
|
|
}
|
|
|
|
|
|
|
|
func zlibEncode(str []byte) []byte {
|
2017-06-19 04:50:38 +05:30
|
|
|
var buff bytes.Buffer
|
|
|
|
writer := zlib.NewWriter(&buff)
|
|
|
|
writer.Write(str)
|
|
|
|
writer.Close()
|
|
|
|
|
|
|
|
return buff.Bytes()
|
|
|
|
}
|
|
|
|
|
2017-06-30 21:10:25 +05:30
|
|
|
func zlibDecode(bts []byte) ([]byte, error) {
|
2017-06-19 04:50:38 +05:30
|
|
|
buff := bytes.NewReader(bts)
|
|
|
|
reader, readError := zlib.NewReader(buff)
|
|
|
|
if readError != nil {
|
|
|
|
return nil, readError
|
|
|
|
}
|
|
|
|
|
|
|
|
resultBuffer := new(bytes.Buffer)
|
|
|
|
io.Copy(resultBuffer, reader)
|
|
|
|
reader.Close()
|
|
|
|
|
|
|
|
return resultBuffer.Bytes(), nil
|
|
|
|
}
|