Senior
Tell me about Redis
sobes.tech AI
Answer from AI
Redis is a high-performance in-memory data store supporting various data structures: strings, lists, sets, hashes, sorted sets, and more. It is used as a cache, message broker, and low-latency database.
In Go, the go-redis library is often used to work with Redis.
Example of simple usage:
package main
import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
)
func main() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
err := rdb.Set(ctx, "key", "value", 0).Err()
if err != nil {
panic(err)
}
val, err := rdb.Get(ctx, "key").Result()
if err != nil {
panic(err)
}
fmt.Println("key", val)
}
Redis supports atomic operations, transactions, Lua scripts, which allow for efficient synchronization and caching tasks.