simpleredis

package module
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

README

simpleredis

Minimal go redis with only get, set and delete operation.
It supports password authentication with redis. With NO external dependencies.

Example

import simpleredis "github.com/maxlerebourg/simpleredis"

var redis simpleredis.SimpleRedis

redis.Init("redis:6379", "", "") // redisHost, redisPass, redisDatabase

err := redis.Set("test", []bytes("whatever"), 60),  // Set key "test" with "whatever" for 60 seconds
if err != nil {
  ...
}
val, err := redis.Get("test") // get key test
if err != nil {
  // err could be only redis:unreachable, redis:miss or redis:timeout available in simpleredis.RedisUnreachable
  ...
}
err = redis.Del("test")
if err != nil {
  ...
}

Author

Max Lerebourg @ Primadviz.com Mathieu Hanotaux

Documentation

Overview

Package simpleredis implements utility routines for interacting. It supports currently the following operations: GET, SET, DELETE, and support timetoleave for keys.

Index

Constants

View Source
const (
	RedisUnreachable = "redis:unreachable"
	RedisMiss        = "redis:miss"
	RedisTimeout     = "redis:timeout"
	RedisNoAuth      = "redis:noauth"
	RedisIssue       = "redis:issue?"
)

Error strings for redis.

Variables

This section is empty.

Functions

This section is empty.

Types

type SimpleRedis

type SimpleRedis struct {
	// contains filtered or unexported fields
}

A SimpleRedis is used to communicate with redis.

func (*SimpleRedis) Del

func (sr *SimpleRedis) Del(name string) error

Del removes the key name in redis.

func (*SimpleRedis) Get

func (sr *SimpleRedis) Get(name string) ([]byte, error)

Get fetches the value for key name in redis.

func (*SimpleRedis) Init

func (sr *SimpleRedis) Init(host, pass, database string)

Init sets the redisHost used to connect to redis.

func (*SimpleRedis) Set

func (sr *SimpleRedis) Set(name string, data []byte, duration int64) error

Set updates the value for key name in redis with value data for duration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL