当前位置:网站首页>Golang operation redis: write and read hash type data
Golang operation redis: write and read hash type data
2022-07-03 06:38:00 【Learn programming notes】
golang operation redis: write in 、 Read hash Type data
Code
package main
import (
"fmt"
"github.com/garyburd/redigo/redis" // introduce redis package
)
func main() {
// adopt go towards redis Write data and read data
//1. link to redis
conn, err := redis.Dial("tcp", "127.0.0.1:6379")
if err != nil {
fmt.Println("redis.Dial err=", err)
return
}
defer conn.Close() // close ..
//2. adopt go towards redis Write data string [key-val]
_, err = conn.Do("HSet", "user01", "name", "john")
if err != nil {
fmt.Println("hset err=", err)
return
}
_, err = conn.Do("HSet", "user01", "age", 18)
if err != nil {
fmt.Println("hset err=", err)
return
}
//3. adopt go towards redis Reading data
r1, err := redis.String(conn.Do("HGet","user01", "name"))
if err != nil {
fmt.Println("hget err=", err)
return
}
r2, err := redis.Int(conn.Do("HGet","user01", "age"))
if err != nil {
fmt.Println("hget err=", err)
return
}
// Because back r yes interface{}
// because name The corresponding value is string , So we need to switch
//nameString := r.(string)
fmt.Printf(" operation ok r1=%v r2=%v \n", r1, r2)
}
result


边栏推荐
- Paper notes vsalm literature review "a comprehensive survey of visual slam algorithms"
- 【5G NR】UE注册流程
- Shell conditional statement
- 【无标题】
- How matlab modifies default settings
- opencv
- 使用conda创建自己的深度学习环境
- Push box games C #
- SQL implementation merges multiple rows of records into one row
- Pytest attempts to execute the test case without skipping, but the case shows that it is all skipped
猜你喜欢

如何迁移或复制VMware虚拟机系统

Operation principle of lua on C: Foundation

Summary of the design and implementation of the weapon system similar to the paladin of vitality

Use abp Zero builds a third-party login module (I): Principles

SQL implementation merges multiple rows of records into one row

The list of "I'm crazy about open source" was released in the first week, with 160 developers on the list

golang操作redis:写入、读取hash类型数据

Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide

Simple understanding of ThreadLocal

Kubesphere - build MySQL master-slave replication structure
随机推荐
A letter to graduating college students
Create your own deep learning environment with CONDA
Support vector machine for machine learning
Climb movie paradise 2021 hot
The win7 computer can't start. Turn the CPU fan and stop it
Difference between shortest path and minimum spanning tree
IE browser flash back, automatically open edge browser
conda和pip的区别
Opencv mouse and keyboard events
HMS core helps baby bus show high-quality children's digital content to global developers
Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
学习笔记 -- k-d tree 和 ikd-Tree 原理及对比
Docker advanced learning (container data volume, MySQL installation, dockerfile)
Some thoughts on machine learning
远端rostopic的本地rviz调用及显示
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
Scripy learning
利用C#实现Pdf转图片
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
Interesting research on mouse pointer interaction