Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/xyproto/simpleredis

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/xyproto/simpleredis

  • v2.8.1+incompatible
  • Source
  • Go
  • Socket score

Version published
Created
Source

Simple Redis

GoDoc Go Report Card

Easy way to use Redis from Go.

Packaging status

Dependencies

Requires Go 1.17 or later.

Online API Documentation

godoc.org

Features and limitations

  • Supports simple use of lists, hashmaps, sets and key/values
  • Deals mainly with strings
  • Uses the redigo package

Example usage

package main

import (
    "log"

    "github.com/xyproto/simpleredis/v2"
)

func main() {
    // Check if the redis service is up
    if err := simpleredis.TestConnection(); err != nil {
        log.Fatalln("Could not connect to Redis. Is the service up and running?")
    }

    // For checking if a Redis server on a specific host:port is up.
    // simpleredis.TestConnectionHost("localhost:6379")

    // Create a connection pool, connect to the given redis server
    pool := simpleredis.NewConnectionPool()

    // Use this for connecting to a different redis host/port
    // pool := simpleredis.NewConnectionPoolHost("localhost:6379")

    // For connecting to a different redis host/port, with a password
    // pool := simpleredis.NewConnectionPoolHost("password@redishost:6379")

    // Close the connection pool right after this function returns
    defer pool.Close()

    // Create a list named "greetings"
    list := simpleredis.NewList(pool, "greetings")

    // Add "hello" to the list, check if there are errors
    if list.Add("hello") != nil {
        log.Fatalln("Could not add an item to list!")
    }

    // Get the last item of the list
    if item, err := list.GetLast(); err != nil {
        log.Fatalln("Could not fetch the last item from the list!")
    } else {
        log.Println("The value of the stored item is:", item)
    }

    // Remove the list
    if list.Remove() != nil {
        log.Fatalln("Could not remove the list!")
    }
}

Testing

Redis must be up and running locally for the go test tests to work.

Timeout issues

If there are timeout issues when connecting to Redis, try consulting the Redis latency doctor on the server by running redis-cli and then latency doctor.

Version, license and author

FAQs

Package last updated on 01 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc