Documentation
¶
Overview ¶
The redisdb package defines a Redis database that fulfills the Database interface in models.
Index ¶
- Constants
- Variables
- func KeyFollowers[ID uint32 | int64 | int](nodeID ID) string
- func KeyFollows[ID uint32 | int64 | int](nodeID ID) string
- func KeyNode[ID uint32 | int64 | int](nodeID ID) string
- func ParseNode(nodeMap map[string]string) (*models.Node, error)
- type Database
- func GenerateDB(cl *redis.Client, nodesNum, successorsPerNode int, rng *rand.Rand) (*Database, error)
- func NewDatabase(ctx context.Context, cl *redis.Client) (*Database, error)
- func NewDatabaseConnection(ctx context.Context, cl *redis.Client) (*Database, error)
- func NewDatabaseFromPubkeys(ctx context.Context, cl *redis.Client, pubkeys []string) (*Database, error)
- func SetupDB(cl *redis.Client, DBType string) (*Database, error)
- func (DB *Database) AddNode(ctx context.Context, pubkey string) (uint32, error)
- func (DB *Database) AllNodes(ctx context.Context) ([]uint32, error)
- func (DB *Database) ContainsNode(ctx context.Context, nodeID uint32) bool
- func (DB *Database) FollowCounts(ctx context.Context, nodeIDs ...uint32) ([]int, error)
- func (DB *Database) FollowerCounts(ctx context.Context, nodeIDs ...uint32) ([]int, error)
- func (DB *Database) Followers(ctx context.Context, nodeIDs ...uint32) ([][]uint32, error)
- func (DB *Database) Follows(ctx context.Context, nodeIDs ...uint32) ([][]uint32, error)
- func (DB *Database) NodeByID(ctx context.Context, nodeID uint32) (*models.Node, error)
- func (DB *Database) NodeByKey(ctx context.Context, pubkey string) (*models.Node, error)
- func (DB *Database) NodeIDs(ctx context.Context, pubkeys ...string) ([]*uint32, error)
- func (DB *Database) Pubkeys(ctx context.Context, nodeIDs ...uint32) ([]*string, error)
- func (DB *Database) ScanNodes(ctx context.Context, cursor uint64, limit int) ([]uint32, uint64, error)
- func (DB *Database) Size(ctx context.Context) int
- func (DB *Database) Update(ctx context.Context, delta *models.Delta) error
- func (DB *Database) Validate() error
- type DatabaseFields
Constants ¶
const ( // redis variable names KeyDatabase string = "database" KeyLastNodeID string = "lastNodeID" KeyKeyIndex string = "keyIndex" KeyNodePrefix string = "node:" KeyFollowsPrefix string = "follows:" KeyFollowersPrefix string = "followers:" // redis node HASH fields NodeID string = "id" NodePubkey string = "pubkey" NodeStatus string = "status" NodePromotionTS string = "promotion_TS" NodeDemotionTS string = "demotion_TS" NodeAddedTS string = "added_TS" )
Variables ¶
var ErrNilClient = errors.New("nil redis client pointer")
Functions ¶
func KeyFollowers ¶
KeyFollowers() returns the Redis key for the followers of the specified nodeID
func KeyFollows ¶
KeyFollows() returns the Redis key for the follows of the specified nodeID
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database fulfills the Database interface defined in models
func GenerateDB ¶
func GenerateDB(cl *redis.Client, nodesNum, successorsPerNode int, rng *rand.Rand) (*Database, error)
generates a random mock database of a specified number of nodes and successors per node the successor of a node won't include itself, and won't have repetitions
func NewDatabase ¶
NewDatabase() creates and returns a new Database instance.
func NewDatabaseConnection ¶
NewDatabaseConnection() returns an initialized Database
func NewDatabaseFromPubkeys ¶
func NewDatabaseFromPubkeys(ctx context.Context, cl *redis.Client, pubkeys []string) (*Database, error)
NewDatabaseFromPubkeys() returns an initialized database storing the specified pubkeys.
func (*Database) ContainsNode ¶
ContainsNode() returns wheter the DB contains nodeID. In case of errors returns false.
func (*Database) FollowCounts ¶
func (*Database) FollowerCounts ¶
func (*Database) Followers ¶
Followers() returns a slice containing the follows of each of the specified nodeIDs.
func (*Database) Follows ¶
Follows() returns a slice containing the follows of each of the specified nodeIDs.
func (*Database) NodeIDs ¶
NodeIDs() returns a slice of nodeIDs that correspond with the given slice of pubkeys. If a pubkey is not found, nil is returned
func (*Database) Pubkeys ¶
Pubkeys() returns a slice of pubkeys that correspond with the given slice of nodeIDs. If a nodeID is not found, nil is returned
func (*Database) ScanNodes ¶
func (DB *Database) ScanNodes(ctx context.Context, cursor uint64, limit int) ([]uint32, uint64, error)
ScanNodes() scans over the nodes and returns a batch of nodeIDs of size roughly equal to limit. Limit controls how much "work" is invested in fetching the batch, hence it's not precise in determining the number of nodes returned.
func (*Database) Size ¶
Size() returns the number of nodes in the DB. In case of errors, it returns 0.
type DatabaseFields ¶
type DatabaseFields struct {
LastNodeID int `redis:"lastNodeID"`
}
DatabaseFields are the fields of the Database in Redis. This struct is used for serialize and deserialize.