commit
d6dce245cf
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v9"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// redis 客户端
|
||||
// 此时不会建立连接
|
||||
//client := redis.NewClient(&redis.Options{
|
||||
// Addr: "192.168.157.135:3679",
|
||||
// Username: "default", // ACL 的默认用户名
|
||||
// Password: "yourPassword",
|
||||
// DB: 0,
|
||||
// DialTimeout: 1 * time.Second,
|
||||
//})
|
||||
|
||||
// URL 方式配置选项
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
fmt.Println(client)
|
||||
|
||||
// 执行操作时,需要获取连接
|
||||
status := client.Ping(context.Background())
|
||||
fmt.Println(status.Result())
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v9"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := redis.NewClient(opt)
|
||||
ctx := context.Background()
|
||||
//ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
|
||||
fmt.Println("begin")
|
||||
//defer cancel()
|
||||
//select {
|
||||
//case <-ctx.Done():
|
||||
// fmt.Println(ctx.Err())
|
||||
//}
|
||||
|
||||
_, err = client.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
|
||||
client.Do(ctx, "HTRRLEN", "KEY", "FIELD")
|
||||
s1 := pipe.Get(ctx, "key1")
|
||||
fmt.Println(s1.Result())
|
||||
time.Sleep(3 * time.Second)
|
||||
s2 := pipe.Get(ctx, "key2")
|
||||
fmt.Println(s2.Result())
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v9"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// 添加和获取信息
|
||||
//geoAddGet()
|
||||
|
||||
// 搜索地点成员
|
||||
geoSearch()
|
||||
}
|
||||
|
||||
func geoSearch() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
ctx := context.Background()
|
||||
client.Del(ctx, "cities")
|
||||
cities := []*redis.GeoLocation{
|
||||
{Name: "changsha", Longitude: 113.00000, Latitude: 28.21667},
|
||||
{Name: "beijing", Longitude: 116.41667, Latitude: 39.91667},
|
||||
{Name: "shanghai", Longitude: 121.43333, Latitude: 34.50000},
|
||||
{Name: "guangzhou", Longitude: 113.23333, Latitude: 23.16667},
|
||||
{Name: "shenzhen", Longitude: 114.06667, Latitude: 22.61667},
|
||||
{Name: "tianjin", Longitude: 117.20000, Latitude: 39.13333},
|
||||
{Name: "hangzhou", Longitude: 120.20000, Latitude: 30.26667},
|
||||
{Name: "chengdu", Longitude: 104.06667, Latitude: 30.66667},
|
||||
{Name: "xian", Longitude: 108.95000, Latitude: 34.26667},
|
||||
{Name: "changchun", Longitude: 125.35000, Latitude: 43.88333},
|
||||
{Name: "wulumuqi", Longitude: 87.68333, Latitude: 43.76667},
|
||||
}
|
||||
client.GeoAdd(ctx, "cities", cities...).Result()
|
||||
|
||||
// 搜索某个距离成员距离范围的其他成员
|
||||
// 一,圆的范围,使用成员确定圆心
|
||||
fmt.Println(client.GeoSearch(ctx, "cities", &redis.GeoSearchQuery{
|
||||
Member: "hangzhou",
|
||||
Radius: 1000,
|
||||
RadiusUnit: "km",
|
||||
}).Result())
|
||||
// 可以返回 坐标、距离和Hash
|
||||
fmt.Println(client.GeoSearchLocation(ctx, "cities", &redis.GeoSearchLocationQuery{
|
||||
GeoSearchQuery: redis.GeoSearchQuery{
|
||||
Member: "hangzhou",
|
||||
Radius: 1000,
|
||||
RadiusUnit: "km",
|
||||
},
|
||||
WithCoord: true,
|
||||
WithDist: true,
|
||||
WithHash: true,
|
||||
}).Result())
|
||||
|
||||
// 二,圆的范围,使用坐标确定圆心
|
||||
fmt.Println(client.GeoSearch(ctx, "cities", &redis.GeoSearchQuery{
|
||||
Longitude: 120.20000,
|
||||
Latitude: 30.26667,
|
||||
Radius: 1000,
|
||||
RadiusUnit: "km",
|
||||
}).Result())
|
||||
|
||||
// 三,矩形的范围,使用坐标(成员)确定中心
|
||||
fmt.Println(client.GeoSearch(ctx, "cities", &redis.GeoSearchQuery{
|
||||
Member: "hangzhou",
|
||||
// OR
|
||||
//Longitude: 120.20000,
|
||||
//Latitude: 30.26667,
|
||||
|
||||
// 宽高
|
||||
BoxWidth: 1000,
|
||||
BoxHeight: 1000,
|
||||
BoxUnit: "km",
|
||||
}).Result())
|
||||
|
||||
// 四,搜素结果过滤
|
||||
// 可以返回 坐标、距离和Hash
|
||||
fmt.Println(client.GeoSearchLocation(ctx, "cities", &redis.GeoSearchLocationQuery{
|
||||
GeoSearchQuery: redis.GeoSearchQuery{
|
||||
Member: "hangzhou",
|
||||
Radius: 1000,
|
||||
RadiusUnit: "km",
|
||||
},
|
||||
WithCoord: true,
|
||||
WithDist: true,
|
||||
WithHash: true,
|
||||
}).Result())
|
||||
|
||||
fmt.Println(client.GeoSearchLocation(ctx, "cities", &redis.GeoSearchLocationQuery{
|
||||
GeoSearchQuery: redis.GeoSearchQuery{
|
||||
Member: "hangzhou",
|
||||
Radius: 1000,
|
||||
RadiusUnit: "km",
|
||||
|
||||
//Sort: "DESC", // ASC, DESC
|
||||
Count: 2,
|
||||
CountAny: true,
|
||||
},
|
||||
WithCoord: true,
|
||||
WithDist: true,
|
||||
WithHash: true,
|
||||
}).Result())
|
||||
|
||||
}
|
||||
|
||||
func geoAddGet() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
ctx := context.Background()
|
||||
|
||||
//client.Del(ctx, "cities")
|
||||
|
||||
// 添加
|
||||
fmt.Println(client.GeoAdd(ctx, "cities", &redis.GeoLocation{
|
||||
Name: "changsha",
|
||||
Longitude: 113.00001,
|
||||
Latitude: 28.21667,
|
||||
}).Result())
|
||||
|
||||
cities := []*redis.GeoLocation{
|
||||
{Name: "changsha", Longitude: 113.00000, Latitude: 28.21667},
|
||||
{Name: "beijing", Longitude: 116.41667, Latitude: 39.91667},
|
||||
{Name: "shanghai", Longitude: 121.43333, Latitude: 34.50000},
|
||||
{Name: "guangzhou", Longitude: 113.23333, Latitude: 23.16667},
|
||||
{Name: "shenzhen", Longitude: 114.06667, Latitude: 22.61667},
|
||||
{Name: "tianjin", Longitude: 117.20000, Latitude: 39.13333},
|
||||
{Name: "hangzhou", Longitude: 120.20000, Latitude: 30.26667},
|
||||
{Name: "chengdu", Longitude: 104.06667, Latitude: 30.66667},
|
||||
{Name: "xian", Longitude: 108.95000, Latitude: 34.26667},
|
||||
{Name: "changchun", Longitude: 125.35000, Latitude: 43.88333},
|
||||
{Name: "wulumuqi", Longitude: 87.68333, Latitude: 43.76667},
|
||||
}
|
||||
fmt.Println(client.GeoAdd(ctx, "cities", cities...).Result())
|
||||
|
||||
// 获取信息
|
||||
// 获取坐标
|
||||
poses, _ := client.GeoPos(ctx, "cities", "changsha", "beijing").Result()
|
||||
for _, pos := range poses {
|
||||
fmt.Println(pos)
|
||||
}
|
||||
// 获取 geohash 位置
|
||||
fmt.Println(client.GeoHash(ctx, "cities", "changsha", "beijing").Result())
|
||||
|
||||
// 获取距离
|
||||
fmt.Println(client.GeoDist(ctx, "cities", "changsha", "beijing", "km").Result()) // m km mi ft
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v9"
|
||||
)
|
||||
|
||||
func main() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
ctx := context.Background()
|
||||
|
||||
result := client.HSet(ctx, "students", "42001", "Mashibing", "42002", "GoLang", "42003", "Redis")
|
||||
fmt.Println(result.Result())
|
||||
|
||||
fmt.Println(client.HGetAll(ctx, "students").Result())
|
||||
|
||||
fmt.Println(
|
||||
client.HLen(ctx, "students").
|
||||
Result()) // 3 <nil>
|
||||
|
||||
fmt.Println(
|
||||
client.HRandField(ctx, "students", 2).
|
||||
Result()) // [42003 42001] <nil>, [42002 42003] <nil>
|
||||
fmt.Println(
|
||||
client.HRandField(ctx, "students", -2).
|
||||
Result()) // [42003 42001] <nil>, [42003 42003] <nil>
|
||||
fmt.Println(
|
||||
client.HRandFieldWithValues(ctx, "students", 2).
|
||||
Result()) // [{42002 GoLang} {42003 Redis}] <nil>
|
||||
|
||||
fmt.Println(
|
||||
client.HExists(ctx, "students", "42003").
|
||||
Result()) // true <nil>
|
||||
fmt.Println(
|
||||
client.HExists(ctx, "students", "42006").
|
||||
Result()) // false <nil>
|
||||
|
||||
fmt.Println(
|
||||
client.HDel(ctx, "students", "42003").
|
||||
Result()) // 1 <nil>
|
||||
fmt.Println(
|
||||
client.HExists(ctx, "students", "42003").
|
||||
Result()) // false <nil>
|
||||
|
||||
fmt.Println(
|
||||
client.Do(ctx, "HSTRLEN", "students", "42001").
|
||||
Result()) // 9 <nil>
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v9"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
hyperloglogOp()
|
||||
}
|
||||
|
||||
func hyperloglogOp() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
ctx := context.Background()
|
||||
|
||||
client.Del(ctx, "ViewsUser")
|
||||
// 添加成员
|
||||
client.PFAdd(ctx, "ViewsUser", "zhao", "qian", "sun")
|
||||
// 获取成员数量
|
||||
fmt.Println(client.PFCount(ctx, "ViewsUser").Result())
|
||||
client.PFAdd(ctx, "ViewsUser", "li", "zhou", "sun")
|
||||
fmt.Println(client.PFCount(ctx, "ViewsUser").Result())
|
||||
|
||||
// 合并
|
||||
client.PFAdd(ctx, "user1", "zhao", "qian", "sun")
|
||||
client.PFAdd(ctx, "user2", "li", "zhou", "sun")
|
||||
client.PFMerge(ctx, "users", "user1", "user2")
|
||||
fmt.Println(client.PFCount(ctx, "users").Result())
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v9"
|
||||
)
|
||||
|
||||
func main() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
val, _ := client.Get(ctx, "someKey").Result()
|
||||
fmt.Printf("%#v", val) // ""
|
||||
|
||||
val, err := client.Get(ctx, "someKey").Result()
|
||||
switch {
|
||||
case err == redis.Nil:
|
||||
fmt.Println("key does not exist")
|
||||
case err != nil:
|
||||
fmt.Println("Get failed", err)
|
||||
case val == "":
|
||||
fmt.Println("value is empty")
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v9"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// basic
|
||||
//basic()
|
||||
|
||||
// 集合运算
|
||||
op()
|
||||
}
|
||||
|
||||
func op() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
ctx := context.Background()
|
||||
|
||||
client.Del(ctx, "A")
|
||||
client.Del(ctx, "A")
|
||||
|
||||
client.SAdd(ctx, "A", "1", "2")
|
||||
client.SAdd(ctx, "B", "2", "3")
|
||||
|
||||
// 交集
|
||||
fmt.Println(client.SInter(ctx, "A", "B").Result())
|
||||
// 并集
|
||||
fmt.Println(client.SUnion(ctx, "A", "B").Result())
|
||||
// 差集
|
||||
fmt.Println(client.SDiff(ctx, "A", "B").Result())
|
||||
fmt.Println(client.SDiff(ctx, "B", "A").Result())
|
||||
|
||||
// 运算完存储
|
||||
client.SInterStore(ctx, "dest", "A", "B")
|
||||
fmt.Println(client.SMembers(ctx, "dest").Result())
|
||||
}
|
||||
|
||||
func basic() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
ctx := context.Background()
|
||||
|
||||
client.Del(ctx, "ips")
|
||||
|
||||
// 添加
|
||||
client.SAdd(ctx, "ips", "129.66.122.123")
|
||||
fmt.Println(client.SMembers(ctx, "ips").Result())
|
||||
client.SAdd(ctx, "ips", "129.66.122.123", "129.66.122.124", "129.66.122.125")
|
||||
// 获取测试
|
||||
fmt.Println(client.SMembers(ctx, "ips").Result())
|
||||
|
||||
// 随机获取一个
|
||||
fmt.Println(client.SRandMember(ctx, "ips").Result())
|
||||
fmt.Println(client.SRandMember(ctx, "ips").Result())
|
||||
fmt.Println(client.SRandMember(ctx, "ips").Result())
|
||||
// 多个
|
||||
fmt.Println(client.SRandMemberN(ctx, "ips", 2).Result())
|
||||
fmt.Println(client.SRandMemberN(ctx, "ips", 2).Result())
|
||||
fmt.Println(client.SRandMemberN(ctx, "ips", 2).Result())
|
||||
// 获取全部
|
||||
fmt.Println(client.SMembers(ctx, "ips").Result())
|
||||
|
||||
// 取出成员,获取成员,并删除
|
||||
//fmt.Println(client.SPop(ctx, "ips").Result())
|
||||
//fmt.Println(client.SMembers(ctx, "ips").Result())
|
||||
|
||||
// 统计成员信息
|
||||
fmt.Println(client.SCard(ctx, "ips").Result())
|
||||
|
||||
// 删除成员
|
||||
client.SRem(ctx, "ips", "129.66.122.124")
|
||||
fmt.Println(client.SMembers(ctx, "ips").Result())
|
||||
|
||||
fmt.Println(client.SCard(ctx, "ips").Result())
|
||||
|
||||
fmt.Println(client.SIsMember(ctx, "ips", "129.66.122.124").Result())
|
||||
fmt.Println(client.SIsMember(ctx, "ips", "129.66.122.123").Result())
|
||||
fmt.Println(client.SMIsMember(ctx, "ips", "129.66.122.124", "129.66.122.123").Result())
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v9"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 设置获取
|
||||
//setGet()
|
||||
|
||||
// 递增、递减、追加
|
||||
//appendIncrDecr()
|
||||
|
||||
// 子串操作
|
||||
sub()
|
||||
}
|
||||
|
||||
// 子串操作
|
||||
func sub() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
ctx := context.Background()
|
||||
|
||||
client.Set(ctx, "name", "MaShiBing", 0)
|
||||
|
||||
// GetRange
|
||||
//fmt.Println(client.GetRange(ctx, "name", 0, 4).Result())
|
||||
//fmt.Println(client.GetRange(ctx, "name", -4, -1).Result())
|
||||
//fmt.Println(client.GetRange(ctx, "name", -4, 16).Result())
|
||||
//fmt.Println(client.GetRange(ctx, "name", -16, 16).Result())
|
||||
//// 全部内容
|
||||
//fmt.Println(client.GetRange(ctx, "name", 0, -1).Result())
|
||||
|
||||
// SetRange
|
||||
//client.SetRange(ctx, "name", 0, "Go")
|
||||
//fmt.Println(client.Get(ctx, "name").Result())
|
||||
//client.SetRange(ctx, "name", 4, "Go")
|
||||
//fmt.Println(client.Get(ctx, "name").Result())
|
||||
|
||||
client.SetRange(ctx, "name", 4, "GoRedisGo")
|
||||
fmt.Println(client.Get(ctx, "name").Result())
|
||||
|
||||
}
|
||||
|
||||
// 递增、递减、追加
|
||||
func appendIncrDecr() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
ctx := context.Background()
|
||||
|
||||
// append
|
||||
//client.Set(ctx, "name", "Ma", 0)
|
||||
//// "Ma" + "Shi"
|
||||
//client.Append(ctx, "name", "Shi")
|
||||
//status := client.Append(ctx, "name", "Bing")
|
||||
//fmt.Println(status.Result())
|
||||
//result := client.Get(ctx, "name")
|
||||
//fmt.Println(result.Result())
|
||||
|
||||
// incr, decr
|
||||
client.Set(ctx, "counter", "0", 0)
|
||||
client.Incr(ctx, "counter")
|
||||
client.Incr(ctx, "counter")
|
||||
client.Incr(ctx, "counter")
|
||||
result := client.Get(ctx, "counter")
|
||||
fmt.Println(result.Result())
|
||||
client.IncrBy(ctx, "counter", 3)
|
||||
client.IncrBy(ctx, "counter", 3)
|
||||
fmt.Println(client.Get(ctx, "counter").Result())
|
||||
client.Decr(ctx, "counter")
|
||||
client.Decr(ctx, "counter")
|
||||
fmt.Println(client.Get(ctx, "counter").Result())
|
||||
client.DecrBy(ctx, "counter", 3)
|
||||
client.DecrBy(ctx, "counter", 3)
|
||||
fmt.Println(client.Get(ctx, "counter").Result())
|
||||
}
|
||||
|
||||
// 设置获取
|
||||
func setGet() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
ctx := context.Background()
|
||||
|
||||
// 设置
|
||||
//status := client.Set(ctx, "name", "", 3*time.Second)
|
||||
// 有效期
|
||||
// 0 表示永不过期
|
||||
//status := client.Set(ctx, "name", "MaShiBing", 0)
|
||||
// KeepTTL -1,表示保持原有的有效期
|
||||
// 仅仅需要修改值,而不去更新有效期的话
|
||||
//status := client.Set(ctx, "name", "MaShiBing", redis.KeepTTL)
|
||||
|
||||
// 设置条件
|
||||
// NX, key 不存在时设置
|
||||
// XX, key 存在时设置
|
||||
status := client.SetArgs(ctx, "name", "mashibing", redis.SetArgs{
|
||||
// 不存在才设置
|
||||
//Mode: "NX",
|
||||
// 存在时才设置
|
||||
Mode: "XX",
|
||||
// Mode "" 表示存在则更新,不存在则添加,是默认的模式
|
||||
// 有效期,时间周期
|
||||
TTL: 0,
|
||||
// 有效期,时间点
|
||||
ExpireAt: time.Time{},
|
||||
// 是否返回原有值
|
||||
Get: false,
|
||||
// 是否保持原有有效期
|
||||
KeepTTL: false,
|
||||
})
|
||||
|
||||
fmt.Println(status.Result())
|
||||
|
||||
// 获取
|
||||
// 执行命令
|
||||
//result := client.Get(ctx, "name")
|
||||
//// 获取结果,以及命令的执行结果(是否有错误)
|
||||
//val, err := result.Result()
|
||||
//
|
||||
//// 判定 key 是否存在(错误)
|
||||
//if err == redis.Nil {
|
||||
// fmt.Println("key not exists")
|
||||
//} else if err != nil {
|
||||
// fmt.Println(err)
|
||||
//} else if val == "" {
|
||||
// fmt.Println("value is empty")
|
||||
//} else {
|
||||
// fmt.Println("get value:", val)
|
||||
//}
|
||||
}
|
@ -0,0 +1 @@
|
||||
package main
|
@ -0,0 +1,12 @@
|
||||
services:
|
||||
db:
|
||||
container_name: simpleCmsMysql
|
||||
image: mysql
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: secret
|
||||
MYSQL_DATABASE: simpleCms
|
||||
ports:
|
||||
- "3316:3306"
|
||||
volumes:
|
||||
- ./data/db:/var/lib/mysql
|
@ -0,0 +1,9 @@
|
||||
module mashibing/redisCli
|
||||
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/go-redis/redis/v9 v9.0.0-rc.1 // indirect
|
||||
)
|
@ -0,0 +1,6 @@
|
||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/go-redis/redis/v9 v9.0.0-rc.1 h1:/+bS+yeUnanqAbuD3QwlejzQZ+4eqgfUtFTG4b+QnXs=
|
||||
github.com/go-redis/redis/v9 v9.0.0-rc.1/go.mod h1:8et+z03j0l8N+DvsVnclzjf3Dl/pFHgRk+2Ct1qw66A=
|
@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "github.com/go-redis/redis/v9"
|
||||
|
||||
var citiesDemo = []*redis.GeoLocation{
|
||||
{Name: "chansha", Longitude: 113.00000, Latitude: 28.21667},
|
||||
{Name: "beijing", Longitude: 116.41667, Latitude: 39.91667},
|
||||
{Name: "shanghai", Longitude: 121.43333, Latitude: 34.50000},
|
||||
{Name: "guangzhou", Longitude: 113.23333, Latitude: 23.16667},
|
||||
{Name: "shenzhen", Longitude: 114.06667, Latitude: 22.61667},
|
||||
{Name: "tianjin", Longitude: 117.20000, Latitude: 39.13333},
|
||||
{Name: "hangzhou", Longitude: 120.20000, Latitude: 30.26667},
|
||||
{Name: "chengdu", Longitude: 104.06667, Latitude: 30.66667},
|
||||
{Name: "xian", Longitude: 108.95000, Latitude: 34.26667},
|
||||
{Name: "changchun", Longitude: 125.35000, Latitude: 43.88333},
|
||||
{Name: "wulumuqi", Longitude: 87.68333, Latitude: 43.76667},
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import "github.com/go-redis/redis/v9"
|
||||
|
||||
func main() {
|
||||
opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := redis.NewClient(opt)
|
||||
//client.BitCount
|
||||
}
|
Loading…
Reference in new issue