github.com/therealbill/libredis@v0.0.0-20161227004305-7d50abda5ccf/client/hyperloglog.go (about) 1 package client 2 3 // PFAdd adds all the element arguments to the HyperLogLog data structure 4 // stored at the variable name specified as first argument. 5 func (r *Redis) PFAdd(key string, elements ...string) (int64, error) { 6 args := packArgs("PFADD", key, elements) 7 rp, err := r.ExecuteCommand(args...) 8 if err != nil { 9 return 0, err 10 } 11 return rp.IntegerValue() 12 } 13 14 // PFCount returns the approximated cardinality computed by the HyperLogLog 15 // data structure stored at the specified variable, 16 // which is 0 if the variable does not exist. 17 // When called with multiple keys, returns the approximated cardinality of 18 // the union of the HyperLogLogs passed, by internally merging the HyperLogLogs 19 // stored at the provided keys into a temporary hyperLogLog. 20 func (r *Redis) PFCount(keys ...string) (int64, error) { 21 args := packArgs("PFCOUNT", keys) 22 rp, err := r.ExecuteCommand(args...) 23 if err != nil { 24 return 0, err 25 } 26 return rp.IntegerValue() 27 } 28 29 // PFMerge merges multiple HyperLogLog values into an unique value 30 // that will approximate the cardinality of the union of the observed 31 // Sets of the source HyperLogLog structures. 32 // The computed merged HyperLogLog is set to the destination variable, 33 // which is created if does not exist (defauling to an empty HyperLogLog). 34 func (r *Redis) PFMerge(destkey string, sourcekeys ...string) error { 35 args := packArgs("PFMERGE", destkey, sourcekeys) 36 rp, err := r.ExecuteCommand(args...) 37 if err != nil { 38 return err 39 } 40 return rp.OKValue() 41 }