Giter Club home page Giter Club logo

simpleredis's Introduction

Simple Redis

Build Status GoDoc

Easy way to use Redis from Go.

Online API Documentation

godoc.org

Features and limitations

  • Supports simple use of lists, hashmaps, sets and key/values
  • Deals mainly with strings
  • Uses the redigo package

Example usage

package main

import (
	"log"

	"github.com/xyproto/simpleredis"
)

func main() {
	// Check if the redis service is up
	if err := simpleredis.TestConnection(); err != nil {
		log.Fatalln("Could not connect to Redis. Is the service up and running?")
	}

	// Use instead for testing if a different host/port is up.
	// simpleredis.TestConnectionHost("localhost:6379")

	// Create a connection pool, connect to the given redis server
	pool := simpleredis.NewConnectionPool()

	// Use this for connecting to a different redis host/port
	// pool := simpleredis.NewConnectionPoolHost("localhost:6379")

	// For connecting to a different redis host/port, with a password
	// pool := simpleredis.NewConnectionPoolHost("password@redishost:6379")

	// Close the connection pool right after this function returns
	defer pool.Close()

	// Create a list named "greetings"
	list := simpleredis.NewList(pool, "greetings")

	// Add "hello" to the list, check if there are errors
	if list.Add("hello") != nil {
		log.Fatalln("Could not add an item to list!")
	}

	// Get the last item of the list
	if item, err := list.GetLast(); err != nil {
		log.Fatalln("Could not fetch the last item from the list!")
	} else {
		log.Println("The value of the stored item is:", item)
	}

	// Remove the list
	if list.Remove() != nil {
		log.Fatalln("Could not remove the list!")
	}
}

Testing

Redis must be up and running locally for the go test tests to work.

Timeout issues

If there are timeout issues when connecting to Redis, try consulting the Redis latency doctor on the server by running redis-cli and then latency doctor.

Version, license and author

  • Version: 2.4
  • License: MIT
  • Author: Alexander F Rødseth

simpleredis's People

Contributors

barracks510 avatar edwardbetts avatar xyproto avatar

Watchers

 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.