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


边栏推荐
- Yolov1 learning notes
- [set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
- 【5G NR】UE注册流程
- Operation principle of lua on C: Foundation
- Create your own deep learning environment with CONDA
- 方差迭代公式推导
- Difference between shortest path and minimum spanning tree
- YOLOV3学习笔记
- 【系统设计】邻近服务
- Judge whether the date time exceeds 31 days
猜你喜欢

ruoyi接口权限校验

Une exploration intéressante de l'interaction souris - pointeur

Simple understanding of ThreadLocal

【系统设计】邻近服务

有意思的鼠標指針交互探究

IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库

Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)

Yolov3 learning notes
![[system design] proximity service](/img/4a/2e68536cbe385af1d1a591e674fbf0.png)
[system design] proximity service

【无标题】
随机推荐
Paper notes vsalm literature review "a comprehensive survey of visual slam algorithms"
Page text acquisition
认识弹性盒子flex
The difference between CONDA and pip
Scroll view specifies the starting position of the scrolling element
Install VM tools
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
YOLOV3学习笔记
Cesium entity (entities) entity deletion method
[system design] proximity service
Unit test framework + Test Suite
Kubesphere - set up redis cluster
Yolov3 learning notes
数值法求解最优控制问题(一)——梯度法
When PHP uses env to obtain file parameters, it gets strings
Luogu problem list: [mathematics 1] basic mathematics problems
ROS+Pytorch的联合使用示例(语义分割)
Various usages of MySQL backup database to create table select and how many days are left
100000 bonus is divided up. Come and meet the "sister who braves the wind and waves" among the winners
Zhiniu stock project -- 04