go_redis_orm

package module
v0.0.0-...-85d4db9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2018 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-redis-orm

redis orm base on protobuf

使用方法
  1. 定义proto。必须有id字段
  2. 通过redis2go.py,生产 redis orm 类

更详细内容,请参见:http://blog.csdn.net/u013272009/article/details/78574079

例子
package main

import (
	"fmt"

	"github.com/fananchong/go-redis-orm"
)

func main() {

	dbName := "db1"

	go_redis_orm.SetNewRedisHandler(go_redis_orm.NewDefaultRedisClient)
	go_redis_orm.CreateDB(dbName, []string{"192.168.1.4:16379"}, "", 0)

	// key值为1的 TestStruct2 数据
	data2 := NewRD_TestStruct2(1)
	data2.F1 = "bbb"
	err := data2.Save(dbName)
	if err != nil {
		panic("#1")
	}

	err = data2.Load(dbName)
	if err == nil {
		if data2.F1 != "bbb" {
			panic("#2")
		}
	} else {
		panic("#3")
	}

	err = data2.Delete(dbName)
	if err != nil {
		panic("#5")
	}

	err = data2.Load(dbName)
	if data2.F1 != "" {
		panic("#6")
	}

	fmt.Println("OK")
}
SetNewRedisHandler接口

本库支持第3方redis客户端整合进本项目,通过调用go_redis_orm.SetNewRedisHandler函数

需要实现go_redis_orm.IClient接口

type IClient interface {
	Get(key string) ([]byte, error)
	Set(key string, data []byte) error
	Del(key string) error
}

例子参考:default_redis_client.go

Redis单机、主从、哨兵、集群搭建

详细参见:http://blog.csdn.net/u013272009/article/details/78513251

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDB

func CreateDB(dbName string, addrs []string, password string, dbindex int)

func SetNewRedisHandler

func SetNewRedisHandler(handler NewRedisType)

Types

type DefaultRedisClient

type DefaultRedisClient struct {
	*goredis.Client
}

func (*DefaultRedisClient) Del

func (this *DefaultRedisClient) Del(key string) error

func (*DefaultRedisClient) Get

func (this *DefaultRedisClient) Get(key string) ([]byte, error)

func (*DefaultRedisClient) Set

func (this *DefaultRedisClient) Set(key string, data []byte) error

type IClient

type IClient interface {
	Get(key string) ([]byte, error)
	Set(key string, data []byte) error
	Del(key string) error
}

func GetDB

func GetDB(dbName string) IClient

func NewDefaultRedisClient

func NewDefaultRedisClient(dbName string, addrs []string, password string, dbindex int) (IClient, error)

type NewRedisType

type NewRedisType func(dbName string, addrs []string, password string, dbindex int) (IClient, error)

type RedisMgr

type RedisMgr struct {
	// contains filtered or unexported fields
}

func NewRedisMgr

func NewRedisMgr() *RedisMgr

func (*RedisMgr) Create

func (this *RedisMgr) Create(dbName string, addrs []string, password string, dbindex int) error

func (*RedisMgr) Get

func (this *RedisMgr) Get(dbName string) IClient

func (*RedisMgr) SetNewRedisHandler

func (this *RedisMgr) SetNewRedisHandler(handler NewRedisType)

Directories

Path Synopsis
Package main is a generated protocol buffer package.
Package main is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址