Convert Figma logo to code with AI

gomodule logoredigo

Go client for Redis

9,738
1,246
9,738
20

Top Related Projects

19,869

Redis Go client

19,865

Redis Go client

Quick Overview

Redigo is a Go client for the Redis database. It offers a simple, efficient, and type-safe API for interacting with Redis, supporting various Redis commands and features. Redigo is widely used in Go applications for Redis integration.

Pros

  • Simple and intuitive API
  • High performance and efficient connection pooling
  • Supports Redis pipelining and transactions
  • Extensive documentation and community support

Cons

  • Lacks some advanced features like automatic reconnection
  • No built-in support for Redis Cluster
  • Limited support for newer Redis features compared to some other clients
  • Manual management of connections required in some cases

Code Examples

  1. Basic connection and key-value operations:
conn, err := redis.Dial("tcp", "localhost:6379")
if err != nil {
    log.Fatal(err)
}
defer conn.Close()

_, err = conn.Do("SET", "key", "value")
if err != nil {
    log.Fatal(err)
}

value, err := redis.String(conn.Do("GET", "key"))
if err != nil {
    log.Fatal(err)
}
fmt.Println("Value:", value)
  1. Using a connection pool:
pool := &redis.Pool{
    MaxIdle:     3,
    IdleTimeout: 240 * time.Second,
    Dial:        func() (redis.Conn, error) { return redis.Dial("tcp", "localhost:6379") },
}

conn := pool.Get()
defer conn.Close()

_, err := conn.Do("SET", "key", "value")
if err != nil {
    log.Fatal(err)
}
  1. Pipelining commands:
conn, err := redis.Dial("tcp", "localhost:6379")
if err != nil {
    log.Fatal(err)
}
defer conn.Close()

conn.Send("SET", "key1", "value1")
conn.Send("SET", "key2", "value2")
conn.Send("GET", "key1")
conn.Send("GET", "key2")
conn.Flush()

for i := 0; i < 4; i++ {
    reply, err := conn.Receive()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Reply %d: %v\n", i, reply)
}

Getting Started

To use Redigo in your Go project, follow these steps:

  1. Install Redigo:

    go get github.com/gomodule/redigo/redis
    
  2. Import the package in your Go code:

    import "github.com/gomodule/redigo/redis"
    
  3. Create a connection to Redis:

    conn, err := redis.Dial("tcp", "localhost:6379")
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close()
    
  4. Start using Redis commands:

    _, err = conn.Do("SET", "mykey", "myvalue")
    if err != nil {
        log.Fatal(err)
    }
    

Competitor Comparisons

19,869

Redis Go client

Pros of go-redis

  • More feature-rich, supporting advanced Redis features like Streams and Pub/Sub
  • Better support for Redis Cluster and Sentinel
  • Active development with frequent updates and improvements

Cons of go-redis

  • Slightly more complex API, which may have a steeper learning curve
  • Higher memory usage due to additional features and abstractions

Code Comparison

redigo:

conn, err := redis.Dial("tcp", "localhost:6379")
defer conn.Close()

_, err = conn.Do("SET", "key", "value")
value, err := redis.String(conn.Do("GET", "key"))

go-redis:

client := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
defer client.Close()

err := client.Set("key", "value", 0).Err()
value, err := client.Get("key").Result()

Both libraries offer similar basic functionality, but go-redis provides a more idiomatic Go API with method chaining and built-in result parsing. redigo requires manual connection management and explicit type conversion for results.

While redigo is simpler and more lightweight, go-redis offers a richer feature set and better support for complex Redis deployments. The choice between them depends on your specific requirements and preferences.

19,865

Redis Go client

Pros of go-redis

  • More feature-rich, supporting advanced Redis features like Streams and Pub/Sub
  • Better support for Redis Cluster and Sentinel
  • Active development with frequent updates and improvements

Cons of go-redis

  • Slightly more complex API, which may have a steeper learning curve
  • Higher memory usage due to additional features and abstractions

Code Comparison

redigo:

conn, err := redis.Dial("tcp", "localhost:6379")
defer conn.Close()

_, err = conn.Do("SET", "key", "value")
value, err := redis.String(conn.Do("GET", "key"))

go-redis:

client := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
defer client.Close()

err := client.Set("key", "value", 0).Err()
value, err := client.Get("key").Result()

Both libraries offer similar basic functionality, but go-redis provides a more idiomatic Go API with method chaining and built-in result parsing. redigo requires manual connection management and explicit type conversion for results.

While redigo is simpler and more lightweight, go-redis offers a richer feature set and better support for complex Redis deployments. The choice between them depends on your specific requirements and preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Redigo

GoDoc

Redigo is a Go client for the Redis database.

Features

Documentation

Installation

Install Redigo using the "go get" command:

go get github.com/gomodule/redigo/redis

The Go distribution is Redigo's only dependency.

Related Projects

Contributing

See CONTRIBUTING.md.

License

Redigo is available under the Apache License, Version 2.0.