Redis client library for Go

Overview

go-redis

go-redis is a Redis client library for the Go programming language. It's built on the skeleton of gomemcache.

It is safe to use by multiple goroutines, and scales well by automatically making new connections to redis on demand. Idle connections stay in the connection pool until time out.

Licensed under the Apache License, Version 2.0.

Status

The library is stable and has been extensively tested on freegeoip.net as the underlying quota mechanism on Redis. It has served dozens of billions of queries that used this library to manage usage.

It is incomplete, though. Me, @gleicon, @lxfontes and others have only implemented the commands we needed for our applications so far, and continue doing so with no rush or schedule. See commands.go for a list of supported commands - they're in alphabetical order. Contributors are welcome.

We've written other Redis client libraries before, also very stable and used in large deployments by major companies.

Build Status

Installing

Make sure Go is installed, and both $GOROOT and $GOPATH are set, then run:

$ go get github.com/fiorix/go-redis/redis

Usage

Hello world:

import "github.com/fiorix/go-redis/redis"

func main() {
	rc := redis.New("10.0.0.1:6379", "10.0.0.2:6379", "10.0.0.3:6379")
	rc.Set("foo", "bar")

	v, err := rc.Get("foo")
	...
}

When connected to multiple servers, commands such as PING, INFO and similar are only executed on the first server. GET, SET and others are distributed by their key.

New connections are created on demand, and stay available in the connection pool until they time out. The library scales very well under high load.

Unix socket, dbid and password support

The client supports ip:port or unix socket for connecting to redis.

rc := redis.New("/tmp/redis.sock db=5 passwd=foobared")

Database ID and password can only be set by New() and can't be changed later. If that is required, make a new connection.

Credits

Thanks to (in no particular order):

  • gomemcache: for the skeleton of this client library.
Issues
  • SIsMember should return bool

    SIsMember should return bool

    From http://redis.io/commands/sismember

    • 1 if the element is a member of the set.
    • 0 if the element is not a member of the set, or if key does not exist.

    Right now we return 0/1 but this is clearly a bool

    opened by lxfontes 3
  • Expose the execWithKey, execOnFirst or add some kind of

    Expose the execWithKey, execOnFirst or add some kind of "Raw" command

    I'm having the wish to implement a custom command, or just to execute "DEBUG SLEEP 0.5", which is not currently implemented. Because execOnFirst is not public, I'd have to either modify your sources to add some kind of Raw command, or to make the execOnFirst public so I could do it outside of the package.

    This works for me, can I submit a PR?

    func (c *Client) Raw(message ...interface{}) (string, error) {
            v, err := c.execOnFirst(false, message...);
            if err != nil {
                    return "", err
            }
            return iface2str(v);
    }
    
    opened by titpetric 1
  • Introduce Lrem

    Introduce Lrem

    I implemented LREM because I needed it for my first Go project. It has the signature LRem(key string, count int, value string) (int, error) where key is a Redis list and count is the number of elements to delete, provided they are equal to value. It returns the number of affected elements.

    opened by devlinzed 1
  • /usr/lib/go/src/pkg/github.com/fiorix/go-redis/redis/redis.go:265: function ends without a return statement

    /usr/lib/go/src/pkg/github.com/fiorix/go-redis/redis/redis.go:265: function ends without a return statement

    Hello,

    I get an error when I try to install:

    [email protected]:~$ go get github.com/fiorix/go-redis/redis
    # github.com/fiorix/go-redis/redis
    /usr/lib/go/src/pkg/github.com/fiorix/go-redis/redis/redis.go:265: function ends without a return statement
    

    Regards,

    opened by Rudloff 1
Owner
Alexandre Fiori
Alexandre Fiori
GoBigdis is a persistent database that implements the Redis server protocol. Any Redis client can interface with it and start to use it right away.

GoBigdis GoBigdis is a persistent database that implements the Redis server protocol. Any Redis client can interface with it and start to use it right

Riccardo 5 Apr 27, 2022
Bxd redis benchmark - Redis benchmark tool for golang

使用 redis benchmark 工具, 测试 10 20 50 100 200 1k 5k 字节 value 大小,redis get set 性能。 r

bingxindan 0 Jan 22, 2022
Redisx: a library of Go utilities built on the redigo redis client library

redisx redisx is a library of Go utilities built on the redigo redis client libr

null 1 Dec 24, 2021
Redis client library for Go

go-redis go-redis is a Redis client library for the Go programming language. It's built on the skeleton of gomemcache. It is safe to use by multiple g

Alexandre Fiori 45 Jul 15, 2020
redis client implement by golang, inspired by jedis.

godis redis client implement by golang, refers to jedis. this library implements most of redis command, include normal redis command, cluster command,

piaohao 105 Jul 20, 2022
Go client for Redis

Redigo Redigo is a Go client for the Redis database. Features A Print-like API with support for all Redis commands. Pipelining, including pipelined tr

null 9.2k Jul 28, 2022
Type-safe Redis client for Golang

Redis client for Golang ❤️ Uptrace.dev - distributed traces, logs, and errors in one place Join Discord to ask questions. Documentation Reference Exam

null 15k Aug 2, 2022
Go Redis Client

xredis Built on top of github.com/garyburd/redigo with the idea to simplify creating a Redis client, provide type safe calls and encapsulate the low l

Raed Shomali 18 Jan 23, 2022
godis - an old Redis client for Go

godis Implements a few database clients for Redis. There is a stable client and an experimental client, redis and exp, respectively. To use any of the

Simon Zimmermann 86 Apr 16, 2022
Google Go Client and Connectors for Redis

Go-Redis Go Clients and Connectors for Redis. The initial release provides the interface and implementation supporting the (~) full set of current Red

Joubin Houshyar 440 Jul 9, 2022
Type-safe Redis client for Golang

Redis client for Golang ❤️ Uptrace.dev - distributed traces, logs, and errors in one place Join Discord to ask questions. Documentation Reference Exam

null 15k Aug 1, 2022
Redis client for Golang

Redis client for Golang To ask questions, join Discord or use Discussions. Newsl

null 0 Dec 23, 2021
Redis client for Golang

Redis client for Golang Discussions. Newsletter to get latest updates. Documentation Reference Examples RealWorld example app Other projects you may l

null 0 Dec 30, 2021
High-performance framework for building redis-protocol compatible TCP servers/services

Redeo The high-performance Swiss Army Knife for building redis-protocol compatible servers/services. Parts This repository is organised into multiple

Black Square Media 416 Aug 3, 2022
Simple key-value store abstraction and implementations for Go (Redis, Consul, etcd, bbolt, BadgerDB, LevelDB, Memcached, DynamoDB, S3, PostgreSQL, MongoDB, CockroachDB and many more)

gokv Simple key-value store abstraction and implementations for Go Contents Features Simple interface Implementations Value types Marshal formats Road

Philipp Gillé 452 Aug 2, 2022
Redis Sorted Sets Benchmark

redis-zbench-go Redis Sorted Sets Benchmark Overview This repo contains code to trigger load ( ZADD ) or query (ZRANGEBYLEX key min max) benchmarks, w

filipe oliveira 3 May 18, 2021
Use Redis' MONITOR to draw things in a terminal

Redis Top Redistop uses MONITOR to watch Redis commands and shows per command and per host statistics. Because MONITOR streams back all commands, its

Factory 29 Jun 21, 2022
Examples and code to assign a name to your MongoDB, MySQL, PostgreSQL, RabbitMQ, and redis connection.

your connection deserves a name ?? When your app interacts with an external system, assign a name to the connection. An external system in this contex

Andy Grunwald 25 Feb 15, 2022
redis protocol server for go.

redigosrv what redis server侧的golang版本实现。 why 作为后端RD,你开发的,维护的最多的应该就是你的server,作为服务的提供方来说,想要和客户端进行有效的交互,首先要要能理解信息的含义,因此一套通信协议是必须的。 为什么选择redis协议,应用层有很多成熟的

Saner 7 Nov 30, 2021