当前位置:网站首页>Golang operation redis: write and read kV data
Golang operation redis: write and read kV data
2022-07-03 06:38:00 【Learn programming notes】
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("Set", "name", "tomjerry Cat and cat ")
if err != nil {
fmt.Println("set err=", err)
return
}
//3. adopt go towards redis Reading data string [key-val]
r, err := redis.String(conn.Do("Get", "name"))
if err != nil {
fmt.Println("set err=", err)
return
}
// Because back r yes interface{}
// because name The corresponding value is string , So we need to switch
//nameString := r.(string)
fmt.Println(" operation ok ", r)
}
result


边栏推荐
- Code management tools
- Selenium ide installation recording and local project maintenance
- Docker advanced learning (container data volume, MySQL installation, dockerfile)
- The win7 computer can't start. Turn the CPU fan and stop it
- ROS+Pytorch的联合使用示例(语义分割)
- Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
- 修改MySQL密码
- Request weather interface format, automation
- conda和pip的区别
- MATLAB如何修改默认设置
猜你喜欢
随机推荐
【code】偶尔取值、判空、查表、验证等
Yolov3 learning notes
Oracle Database Introduction
pytorch练习小项目
Time format record
(翻译)异步编程:Async/Await在ASP.NET中的介绍
【类和对象】深入浅出类和对象
YOLOV1学习笔记
10万奖金被瓜分,快来认识这位上榜者里的“乘风破浪的姐姐”
Reinstalling the system displays "setup is applying system settings" stationary
Various usages of MySQL backup database to create table select and how many days are left
Mysql5.7 group by error
Kubesphere - build MySQL master-slave replication structure
[5g NR] UE registration process
Use abp Zero builds a third-party login module (I): Principles
远端rostopic的本地rviz调用及显示
Mysql
The mechanical hard disk is connected to the computer through USB and cannot be displayed
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
MATLAB如何修改默认设置









