zset

package
v0.0.0-...-47e3ba9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Example
package main

import "fmt"

var zsetKey = "my_zset"

func main() {
	zset := New()

	zset.ZAdd(zsetKey, 12.1, "PHP")
	zset.ZAdd(zsetKey, 34.23, "Java")
	zset.ZAdd(zsetKey, 23.5, "Python")

	val := zset.ZGetByRank(zsetKey, 2)
	for _, v := range val {
		fmt.Printf("%+v", v)
	}

	zset.ZRange(zsetKey, 1, 10)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SortedSet

type SortedSet struct {
	// contains filtered or unexported fields
}

SortedSet sorted set struct

func New

func New() *SortedSet

New create a new sorted set.

func (*SortedSet) ZAdd

func (z *SortedSet) ZAdd(key string, score float64, member string)

ZAdd Adds the specified member with the specified score to the sorted set stored at key.

func (*SortedSet) ZCard

func (z *SortedSet) ZCard(key string) int

ZCard returns the sorted set cardinality (number of elements) of the sorted set stored at key.

func (*SortedSet) ZClear

func (z *SortedSet) ZClear(key string)

ZClear clear the key in zset.

func (*SortedSet) ZGetByRank

func (z *SortedSet) ZGetByRank(key string, rank int) (val []interface{})

ZGetByRank 根据排名获取member及分值信息,从小到大排列遍历,即分值最低排名为0,依次类推 Get the member at key by rank, the rank is ordered from lowest to highest. The rank of lowest is 0 and so on.

func (*SortedSet) ZIncrBy

func (z *SortedSet) ZIncrBy(key string, increment float64, member string) float64

ZIncrBy increments the score of member in the sorted set stored at key by increment. If member does not exist in the sorted set, it is added with increment as its score (as if its previous score was 0.0). If key does not exist, a new sorted set with the specified member as its sole member is created.

func (*SortedSet) ZKeyExists

func (z *SortedSet) ZKeyExists(key string) bool

ZKeyExists check if the key exists in zset.

func (*SortedSet) ZRange

func (z *SortedSet) ZRange(key string, start, stop int) []interface{}

ZRange returns the specified range of elements in the sorted set stored at <key>.

func (*SortedSet) ZRangeWithScores

func (z *SortedSet) ZRangeWithScores(key string, start, stop int) []interface{}

ZRangeWithScores returns the specified range of elements in the sorted set stored at <key>.

func (*SortedSet) ZRank

func (z *SortedSet) ZRank(key, member string) int64

ZRank returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. The rank (or index) is 0-based, which means that the member with the lowest score has rank 0.

func (*SortedSet) ZRem

func (z *SortedSet) ZRem(key, member string) bool

ZRem removes the specified members from the sorted set stored at key. Non existing members are ignored. An error is returned when key exists and does not hold a sorted set.

func (*SortedSet) ZRevGetByRank

func (z *SortedSet) ZRevGetByRank(key string, rank int) (val []interface{})

ZRevGetByRank get the member at key by rank, the rank is ordered from highest to lowest. The rank of highest is 0 and so on.

func (*SortedSet) ZRevRange

func (z *SortedSet) ZRevRange(key string, start, stop int) []interface{}

ZRevRange returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score.

func (*SortedSet) ZRevRangeWithScores

func (z *SortedSet) ZRevRangeWithScores(key string, start, stop int) []interface{}

ZRevRange returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score.

func (*SortedSet) ZRevRank

func (z *SortedSet) ZRevRank(key, member string) int64

ZRevRank returns the rank of member in the sorted set stored at key, with the scores ordered from high to low. The rank (or index) is 0-based, which means that the member with the highest score has rank 0.

func (*SortedSet) ZRevScoreRange

func (z *SortedSet) ZRevScoreRange(key string, max, min float64) (val []interface{})

ZRevScoreRange returns all the elements in the sorted set at key with a score between max and min (including elements with score equal to max or min). In contrary to the default ordering of sorted sets, for this command the elements are considered to be ordered from high to low scores.

func (*SortedSet) ZScore

func (z *SortedSet) ZScore(key string, member string) (ok bool, score float64)

ZScore returns the score of member in the sorted set at key.

func (*SortedSet) ZScoreRange

func (z *SortedSet) ZScoreRange(key string, min, max float64) (val []interface{})

ZScoreRange returns all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max). The elements are considered to be ordered from low to high scores.

type SortedSetNode

type SortedSetNode struct {
	// contains filtered or unexported fields
}

SortedSetNode node of sorted set

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL