Documentation ¶
Overview ¶
Package hyperloglog contains a Go implementation of the HyperLogLog data structure in Redis.
For more information about how the data structure works, see the Redis documentation or http://antirez.com/news/75.
Example ¶
package main import ( "fmt" "net" "time" "github.com/MasterOfBinary/redistypes/hyperloglog" "github.com/MasterOfBinary/redistypes/internal" "github.com/MasterOfBinary/redistypes/internal/test" "github.com/garyburd/redigo/redis" ) func main() { netConn, errDial := net.Dial("tcp", internal.GetHostAndPort()) if errDial != nil { fmt.Printf("Unable to dial, err: %v", errDial) return } conn := redis.NewConn(netConn, time.Second, time.Second) defer conn.Close() hll := hyperloglog.NewRedisHyperLogLog(conn, test.RandomKey()) count, errCount := hll.Count() if errCount != nil { fmt.Printf("Unable to count items in hll, err: %v", errCount) return } fmt.Println("Count is:", count) }
Output: Count is: 0
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HyperLogLog ¶
type HyperLogLog interface { // Base returns the base Type. Base() redistypes.Type // Add implements the Redis command PFADD. It adds items to the HyperLogLog count. It returns an error or true // if at least one internal register was altered, or false otherwise. // // See https://redis.io/commands/pfadd. Add(args ...interface{}) (bool, error) // Count implements the Redis command PFCOUNT. It returns the count of unique items added to the HyperLogLog, // or an error if something went wrong. // // See https://redis.io/commands/pfcount. Count() (uint64, error) // Merge implements the Redis command PFMERGE. It merges the HyperLogLog with other to produce a new // HyperLogLog with given name. It returns an error or the newly created HyperLogLog. // // See https://redis.io/commands/pfmerge. Merge(name string, other HyperLogLog) (HyperLogLog, error) }
HyperLogLog is a probabilistic data structure that counts the number of unique items added to it.
func NewRedisHyperLogLog ¶
func NewRedisHyperLogLog(conn redis.Conn, name string) HyperLogLog
NewRedisHyperLogLog creates a Redis implementation of HyperLogLog given redigo connection conn and name. The Redis key used to identify the HyperLogLog will be name.
Example ¶
package main import ( "fmt" "net" "time" "github.com/MasterOfBinary/redistypes/hyperloglog" "github.com/MasterOfBinary/redistypes/internal" "github.com/MasterOfBinary/redistypes/internal/test" "github.com/garyburd/redigo/redis" ) func main() { netConn, errDial := net.Dial("tcp", internal.GetHostAndPort()) if errDial != nil { fmt.Printf("Unable to dial, err: %v", errDial) return } conn := redis.NewConn(netConn, time.Second, time.Second) defer conn.Close() hll := hyperloglog.NewRedisHyperLogLog(conn, test.RandomKey()) count, errCount := hll.Count() if errCount != nil { fmt.Printf("Unable to get count, err: %v", errCount) return } fmt.Println("Count:", count) }
Output: Count: 0
Click to show internal directories.
Click to hide internal directories.