Skip to main content

object.go

object.go - Overview

This file defines the core object structures used in DiceDB, including Obj, InternalObj, and ObjectType. It also defines the constants for supported object types and provides a method for converting the ObjectType to a string representation.

Detailed Documentation

Obj

type Obj struct {
Type ObjectType
LastAccessedAt uint32
Value interface{}
}

Purpose: Represents a basic object structure that includes metadata about the object as well as its value.

Fields:

  • Type: A ObjectType field used to store the type of the object.
  • LastAccessedAt: A uint32 field that stores the timestamp representing the last time the object was accessed.
  • Value: An interface{} type that holds the actual data of the object.

InternalObj

type InternalObj struct {
Obj *Obj
ExDuration int64
}

Purpose: An extension of the Obj struct, designed to add extra metadata for more advanced use cases.

Fields:

  • Obj: A pointer to the underlying Obj that contains the core object data.
  • ExDuration: Represents a time-based property, such as the duration for which the object is valid.

ObjectType

type ObjectType uint8

Purpose: Represents the type of a DiceDB object.

Constants

const (
ObjTypeString ObjectType = iota
_
_
ObjTypeJSON
ObjTypeByteArray
ObjTypeInt
ObjTypeSet
ObjTypeSSMap
ObjTypeSortedSet
ObjTypeCountMinSketch
ObjTypeBF
ObjTypeDequeue
ObjTypeHLL
ObjTypeFloat
)

Purpose: Defines object types as constants of type ObjectType.

Constants:

  • ObjTypeString: Represents a string object type.
  • ObjTypeJSON: Represents a JSON object type.
  • ObjTypeByteArray: Represents a byte array object type.
  • ObjTypeInt: Represents an integer object type.
  • ObjTypeSet: Represents a set object type.
  • ObjTypeSSMap: Represents a sorted string map object type.
  • ObjTypeSortedSet: Represents a sorted set object type.
  • ObjTypeCountMinSketch: Represents a Count-Min Sketch object type.
  • ObjTypeBF: Represents a Bloom Filter object type.
  • ObjTypeDequeue: Represents a Dequeue object type.
  • ObjTypeHLL: Represents a HyperLogLog object type.
  • ObjTypeFloat: Represents a float object type.

String

func (ot ObjectType) String() string {
names := [...]string{
"string",
"",
"",
"json",
"bytes",
"int",
"set",
"ssmap",
"sortedset",
"countminsketch",
"bf",
"dequeue",
"hll",
"float",
}

if ot < ObjectType(len(names)) {
return names[ot]
}
return "Unknown"
}

Purpose: Returns the name of the object type as a string.

Parameters:

  • ot: The ObjectType to convert to a string.

Returns:

  • string: The string representation of the object type, or "Unknown" if the type is not recognized.

Code Examples

None

Getting Started Relevance