Giter Club home page Giter Club logo

redis's Introduction

redis

redis orm by golang 目前对redis的方法支持不全,需要的时候后期再添加

使用介绍--初始化单个实例

package main

import (
	"github.com/hzxgo/log"
	"github.com/hzxgo/redis"
)

func main() {
	address := "127.0.0.1:6379"
	db := 1
	timeout := 3
	auth := "redis_auth_string"
	// instance := "main"

	// init redis
	// 指定实例名称初始化:redis.Init(address, db, timeout, auth, instance)
	err := redis.Init(address, db, timeout, auth)
	if err != nil {
		log.Errorf("redis init | %v", err)
		return
	}

	// redis set
	// 指定实例:redis.Set(rdsUsername, "hezhixiong", instance)
	rdsUsername := "test:username"
	err = redis.Set(rdsUsername, "hezhixiong")
	if  err != nil {
		log.Errorf("redis set %s | %v", rdsUsername, err)
		return
	}

	// redis get
	username, err := redis.Get(rdsUsername)
	if err != nil {
		log.Errorf("redis get %s | %v", rdsUsername, err)
		return
	}

	log.Infof("username: %s", username)
}

初始化多个实例

rc := make([]*redis.RdsCfg, len(Config.Redis))
	for i, v := range Config.Redis {
		rc[i] = &redis.RdsCfg{
			Instance:  v.Instance,
			Address:   v.Address,
			DB:        v.Db,
			Auth:      v.Auth,
			Timeout:   v.Timeout,
			IsDefault: v.IsDefault,
		}
	}
	if err := redis.BatchInit(rc); err != nil {
		log.Errorf("batch init redis | %v", err)
		return
	}

redis's People

Contributors

hzxgo 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.