当前位置:网站首页>golang操作redis:写入、读取kv数据
golang操作redis:写入、读取kv数据
2022-07-03 06:33:00 【学亮编程手记】
代码
package main
import (
"fmt"
"github.com/garyburd/redigo/redis" //引入redis包
)
func main() {
//通过go 向redis 写入数据和读取数据
//1. 链接到redis
conn, err := redis.Dial("tcp", "127.0.0.1:6379")
if err != nil {
fmt.Println("redis.Dial err=", err)
return
}
defer conn.Close() //关闭..
//2. 通过go 向redis写入数据 string [key-val]
_, err = conn.Do("Set", "name", "tomjerry猫猫")
if err != nil {
fmt.Println("set err=", err)
return
}
//3. 通过go 向redis读取数据 string [key-val]
r, err := redis.String(conn.Do("Get", "name"))
if err != nil {
fmt.Println("set err=", err)
return
}
//因为返回 r是 interface{}
//因为 name 对应的值是string ,因此我们需要转换
//nameString := r.(string)
fmt.Println("操作ok ", r)
}
结果
边栏推荐
- Project summary --2 (basic use of jsup)
- Svn branch management
- In depth learning
- (翻译)异步编程:Async/Await在ASP.NET中的介绍
- Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
- Install VM tools
- . Net program configuration file operation (INI, CFG, config)
- YOLOV1学习笔记
- opencv鼠标键盘事件
- Luogu problem list: [mathematics 1] basic mathematics problems
猜你喜欢
有意思的鼠标指针交互探究
Local rviz call and display of remote rostopic
Push box games C #
JMeter performance automation test
Scroll view specifies the starting position of the scrolling element
[5g NR] UE registration process
[system design] proximity service
论文笔记 VSALM 文献综述《A Comprehensive Survey of Visual SLAM Algorithms》
Project summary --04
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle
随机推荐
How to scan when Canon c3120l is a network shared printer
Openresty best practices
Kubesphere - build MySQL master-slave replication structure
opencv鼠标键盘事件
Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样
简易密码锁
Ruoyi interface permission verification
YOLOV1学习笔记
有意思的鼠標指針交互探究
数值法求解最优控制问题(一)——梯度法
vmware虚拟机C盘扩容
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
致即将毕业大学生的一封信
C2338 Cannot format an argument. To make type T formattable provide a formatter<T> specialization:
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
[untitled] 5 self use history
【无标题】5 自用历程
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
Create your own deep learning environment with CONDA
Scripy learning