Exemple #1
0
func (db *DB) RawPut(key, value []byte, ttl int64) *skv.Reply {

	rpl := skv.NewReply("")

	if len(key) < 2 {
		rpl.Status = skv.ReplyBadArgument
		return rpl
	}

	if ttl > 0 {

		if ttl < 1000 {
			return rpl
		}

		switch key[0] {
		case skv.NsKvEntry:
			if ok := db._raw_ssttlat_put(key[0], key[1:], dbutil.MetaTimeNowAddMS(ttl)); !ok {
				rpl.Status = skv.ReplyBadArgument
				return rpl
			}
		default:
			rpl.Status = skv.ReplyBadArgument
			return rpl
		}
	}

	if err := db.ldb.Put(key, value, nil); err != nil {
		rpl.Status = err.Error()
	}

	return rpl
}
Exemple #2
0
func (m *ObjectMeta) Export() []byte {

	data := make([]byte, 69)

	//
	data[0] = obj_meta_ver
	data[1] = m.Type

	//
	binary.BigEndian.PutUint64(data[12:20], m.Version)
	binary.BigEndian.PutUint64(data[4:12], m.LogVersion)

	//
	if m.Expired == 0 && m.Ttl > 0 {
		m.Expired = dbutil.MetaTimeNowAddMS(m.Ttl)
	}

	binary.BigEndian.PutUint64(data[20:28], m.Created)
	binary.BigEndian.PutUint64(data[28:36], m.Updated)
	binary.BigEndian.PutUint64(data[36:44], m.Expired)

	//
	binary.BigEndian.PutUint32(data[56:60], m.Group)
	binary.BigEndian.PutUint32(data[60:64], m.User)
	binary.BigEndian.PutUint32(data[64:68], m.Mode)

	//
	if m.Type == ObjectTypeFold {
		binary.BigEndian.PutUint32(data[52:56], m.Num)
	} else if m.Type == ObjectTypeGeneral {
		binary.BigEndian.PutUint32(data[52:56], m.Sum)
	}

	//
	binary.BigEndian.PutUint64(data[44:52], m.Size)

	//
	namelen := len(m.Name)
	if namelen > 255 {
		namelen = 255
	}

	if namelen > 0 {
		data[68] = uint8(namelen)
		data = append(data, []byte(m.Name[:namelen])...)
	}

	binary.BigEndian.PutUint16(data[2:4], uint16(len(data)))

	return data
}