Golang学习系列第七天:操作Redis
0 redis安装请参考Redis备忘录
1. golang操作redis
切换到golang工作目录,新建项目redis,然后建立连接redis的文件
编辑redis-conn.go文件 ,即
键入以下代码
执行以上程序
没有报错,表示连接redis成功!!!
1.1 添加键值
通过golang设置redis键值前,请先通过redis shell查询下是否存在
很好键golang并不存在,返回nil
然后通过golang添加键值
执行以上代码
最后通过shell 查看是否键是否设置成功
结果表明通golang设置的键golang的值为yes生效了!!!
1.2 获取键值
获取1.1设置的键值
执行程序,输出结果
其他特性自行发挥!!!
后记: 已把我的电子书已上传至github:https://github.com/dongguangming/dgm-collection/tree/master/%E6%95%B0%E6%8D%AE%E5%BA%93/redis
后续会慢慢上传其他资料。
参考:
-
Golang’s Superior Cache Solution to Memcached and Redis https://www.mailgun.com/blog/golangs-superior-cache-solution-memcached-redis/
-
A tour of the Redis stars https://www.compose.com/articles/a-tour-of-the-redis-stars-2/
-
Getting Started with Redis and Go - Tutorial https://tutorialedge.net/golang/go-redis-tutorial/
-
How to Use Redis Go Client go-redis/redis with GoLang https://kb.objectrocket.com/redis/how-to-use-redis-go-client-go-redis-redis-with-golang-592
-
Golang: Redis cluster client example https://golangbyexample.com/golang-redis-cluster-client-example/
-
go-redisでのRedisデータ型の扱い方 https://qiita.com/momotaro98/items/ed496ba06908b278e103
-
Golang / Go Crash Course 08 | Using Redis as A Cache for our REST API https://m.youtube.com/watch?v=x5GGLrTuQCA
-
使用 Go 语言读写Redis协议 https://colobu.com/2019/04/16/Reading-and-Writing-Redis-Protocol-in-Go/,https://www.redisgreen.net/blog/reading-and-writing-redis-protocol/
-
Distributed Locks using Golang and Redis https://kylewbanks.com/blog/distributed-locks-using-golang-and-redis
-
Go and Compose - Redis, RethinkDB, and RabbitMQ https://www.compose.com/articles/go-and-compose-redis-rethinkdb-and-rabbitmq/