Coder Social home page Coder Social logo

mantle's Introduction

Mantle

Go wrapper for nosql dbs.

####Get the package: go get github.com/goibibo/mantle

####Code: package main

    import (
            "fmt"
            "github.com/goibibo/mantle"
            "time"
    )

    func main(){
            //sample data
            keyValue := map[string]interface{}{"key1":"val1", "key2":"val2", "key3":"val3"}
            //extra params to be passed to connection
            options := map[string]string{"db":"1"}
            hostNPort := []string{"localhost:6379"}

            orm := mantle.Orm{Driver: "redis", HostAndPorts: hostNPort}

            //selecting a particular db
            orm := mantle.Orm{Driver: "redis", HostAndPorts: hostNPort, Options: options}

            //default "localhost:6379 is used when hostAndPort is not passed"
            //orm := mantle.Orm{Driver: "redis"}

            //this connects to redis at localhost:6379 by default
            //orm := mantle.Orm{}

            connection := orm.New()

            fmt.Println(connection.Set("key", "value2")) //output: true
            fmt.Println(connection.Get("key"))           //value2
            fmt.Println(connection.Delete("key"))        //1
            fmt.Println(connection.Get("key"))           //""

            fmt.Println(connection.MSet(keyValue))       //true
            fmt.Println(connection.MGet("key3", "key2")) //[val3 val2]

            connection.Expire("key", 1)
            time.Sleep(1 * time.Second)
            fmt.Println(connection.Get("key"))           //""

            /*Execute any redis command*/
            connection.Execute("LPUSH", "test", "a")
            connection.Execute("LPUSH", "test", "b")
            connection.Execute("LPUSH", "test", "c")
            values, _ := connection.Execute("LRANGE", "test", 0, -1)
            fmt.Println(values)                          //[[99] [98] [97]]

            connection.Setex("key", 1, "value")
            fmt.Println(connection.Get("key"))           //value
            time.Sleep(1 * time.Second)
            fmt.Println(connection.Get("key"))           //""

    }

mantle's People

Contributors

vireshas avatar

Watchers

gaurav avatar James Cloos avatar

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.