Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xyproto/simpleredis
:radio: Simple way to use Redis from Go
https://github.com/xyproto/simpleredis
go redis strings
Last synced: 5 days ago
JSON representation
:radio: Simple way to use Redis from Go
- Host: GitHub
- URL: https://github.com/xyproto/simpleredis
- Owner: xyproto
- License: bsd-3-clause
- Created: 2013-04-04T07:34:06.000Z (almost 12 years ago)
- Default Branch: main
- Last Pushed: 2024-12-01T16:04:16.000Z (2 months ago)
- Last Synced: 2025-01-21T21:03:54.505Z (13 days ago)
- Topics: go, redis, strings
- Language: Go
- Homepage:
- Size: 162 KB
- Stars: 25
- Watchers: 4
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Simple Redis
============[![GoDoc](https://godoc.org/github.com/xyproto/simpleredis?status.svg)](http://godoc.org/github.com/xyproto/simpleredis)
[![Go Report Card](https://goreportcard.com/badge/github.com/xyproto/simpleredis)](https://goreportcard.com/report/github.com/xyproto/simpleredis)Easy way to use Redis from Go.
[![Packaging status](https://repology.org/badge/vertical-allrepos/go:github-xyproto-simpleredis.svg)](https://repology.org/project/go:github-xyproto-simpleredis/versions)
Dependencies
------------Requires Go 1.17 or later.
Online API Documentation
------------------------[godoc.org](http://godoc.org/github.com/xyproto/simpleredis)
Features and limitations
------------------------* Supports simple use of lists, hashmaps, sets and key/values
* Deals mainly with strings
* Uses the [redigo](https://github.com/gomodule/redigo) packageExample usage
-------------~~~go
package mainimport (
"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
---------------------------* Version: 2.8.1
* License: BSD-3
* Author: Alexander F. Rødseth <[email protected]>