GithubHelp home page GithubHelp logo

redis-op's Introduction

基于redigo封装的redis连接

最近在研究golang环境如何更好的使用redis,过程中根据以往的运维经验和个人开发爱好封装了redigo的连接池,以方便以后进行项目的快速开发和学习。

安装和使用

注意:我个人是在golang1.8.3环境下封装的,其他版本不确定会不会有问题

$ go get -v github.com/gomodule/redigo/redis
$ go get -v github.com/xxbandy/redis-op/pool
$ cat test-conn.go
package main
import (
    "fmt"
    "github.com/gomodule/redigo/redis"
    redisop "github.com/xxbandy/redis-op/pool"
)

func main() {
    //创建一个新连接池输入redis的ip,port,passwd
    pool := redisop.NewPool("localhost","6379","passwd")
    defer pool.Close()
    conn := pool.Get()
    defer conn.Close()

    //使用获取到redis连接进行操作
    _,setErr := redis.String(conn.Do("set","bgops","https://xxbandy.github.io"))
    redisop.ErrCheck("set error:",setErr)

    output,_ := redis.String(conn.Do("get","bgops"))
    fmt.Println("blog url:",output)
}
$ go run test-conn.go
blog url: https://xxbandy.github.io

redis-op's People

Contributors

bgbiao avatar

Watchers

James Cloos avatar  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.