当前位置:网站首页>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


边栏推荐
- Page text acquisition
- Simple understanding of bubble sorting
- Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
- UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
- 【无标题】8 简易版通讯录
- 冒泡排序的简单理解
- The mechanical hard disk is connected to the computer through USB and cannot be displayed
- Simple password lock
- Decision tree of machine learning
- Use @data in Lombok to simplify entity class code
猜你喜欢
![[5g NR] UE registration process](/img/e3/f881d51fba03010de8c45ea480f3f0.png)
[5g NR] UE registration process

Read blog type data from mysql, Chinese garbled code - solved
![[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)](/img/a4/00aca72b268f77fe4fb24ac06289f5.jpg)
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)

Ruoyi interface permission verification

Create your own deep learning environment with CONDA

【无标题】

JMeter linked database

ROS+Pytorch的联合使用示例(语义分割)

Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)

Advanced technology management - do you know the whole picture of growth?
随机推荐
2022年华东师范大学计科考研复试机试题-详细题解
Reinstalling the system displays "setup is applying system settings" stationary
卡特兰数(Catalan)的应用场景
YOLOV2学习与总结
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle
10万奖金被瓜分,快来认识这位上榜者里的“乘风破浪的姐姐”
论文笔记 VSALM 文献综述《A Comprehensive Survey of Visual SLAM Algorithms》
Cannot get value with @value, null
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Push box games C #
Scroll view specifies the starting position of the scrolling element
Unit test framework + Test Suite
The list of "I'm crazy about open source" was released in the first week, with 160 developers on the list
Simple understanding of bubble sorting
YOLOV3学习笔记
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
Luogu problem list: [mathematics 1] basic mathematics problems
Chapter 8. MapReduce production experience
Decision tree of machine learning
In depth learning