GithubHelp home page GithubHelp logo

arriqaaq / zset Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 0.0 11 KB

ZSet is an in-memory Redis like sorted set datastructure

License: MIT License

Go 100.00%
redis golang data-structures data-structure skiplist

zset's Introduction

zset

Getting Started

Installing

To start using hash, install Go and run go get:

$ go get -u github.com/arriqaaq/zset

This will retrieve the library.

Usage

package main

import (
	"fmt"

	"github.com/arriqaaq/zset"
)

type kv struct{ k, v int }

func main() {
	key := "zset1"

	// ZAdd (accepts any value)
	n := zset.New()
	n.ZAdd(key, 1, "ced", nil)
	n.ZAdd(key, 1, "efg", &kv{1, 2})

	// ZScore
	_, score := n.ZScore(key, "ced")
	fmt.Println("score: ", int(score))
	// score: 1

	// ZRank
	rank := n.ZRank(key, "ced")
	fmt.Println("zrank: ", int(rank))
	// zrank: 0

	// ZRevRank
	rank = n.ZRevRank(key, "ced")
	fmt.Println("zrevrank: ", int(rank))
	// zrevrank: 1

	// ZIncrBy
	n.ZIncrBy(key, 300, "ced")
	_, score = n.ZScore(key, "ced")
	fmt.Println("score: ", int(score))
	// score: 301
}

Supported Commands

Supported  commands

ZADD
ZCARD
ZINCRBY
ZPOPMAX
ZPOPMIN
ZRANGE
ZRANGEBYSCORE
ZRANGEWITHSSCORES
ZRANK
ZREM
ZREVRANGE
ZREVRANGEWITHSSCORES
ZREVRANK
ZSCORE

zset's People

Contributors

arriqaaq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

zset's Issues

Listed sample code won't compile

Tried to compile the sample code listed in readme file and gives several errors

# command-line-arguments
./a.go:13:28: cannot use 1 (type untyped int) as type string in field value
./a.go:13:30: cannot use 2 (type untyped int) as type string in field value
./a.go:16:23: undefined: testKey
./a.go:17:2: undefined: assert
./a.go:17:15: undefined: t
./a.go:20:18: undefined: testKey
./a.go:21:2: undefined: assert
./a.go:21:15: undefined: t
./a.go:24:7: no new variables on left side of :=
./a.go:29:11: no new variables on left side of :=
./a.go:21:15: too many errors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.