redis

command
v0.0.0-...-a2a1f02 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 3 Imported by: 0

README

redis example

A non-relational (NoSQL) database. SET/GET a key/value pair.

Documentation and reference,

GitHub Webpage

MAKE SURE YOU HAVE REDIS RUNNING

Obviously you need a redis server running,

Check you have one running,

redis-cli ping

RUN

First, make sure you have the go library

go get -u -v github.com/go-redis/redis

Then run,

go run redis.go

Your output should be,

PONG <nil>
jeff monkey
key2 does not exist

CHECK KEY/VALUE USING REDIS-CLI

Check your key value using command line,

redis-cli
get jeff

SET/GET KEY/VALUES IN GO

Lets dive into the code.

CREATE A CONNECTION TO REDIS SERVER
client := redis.NewClient(&redis.Options{
    Addr:     "localhost:6379",
    Password: "", // no password set
    DB:       0,  // use default DB
})

pong, err := client.Ping().Result()
fmt.Println(pong, err)
// Output: PONG <nil>
SET A KEY/VALUE
err = client.Set("jeff", "monkey", 0).Err()
GET A KEY/VALUE
val, err := client.Get("jeff").Result()
fmt.Println("jeff", val)
// Output: jeff monkey

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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