Skip to content

Commit de43ef8

Browse files
committed
modify commands
1 parent e37da15 commit de43ef8

File tree

2 files changed

+159
-230
lines changed

2 files changed

+159
-230
lines changed

commands_test.go

Lines changed: 140 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,208 +1104,148 @@ var _ = Describe("Commands", func() {
11041104
Expect(cursor).NotTo(BeZero())
11051105
})
11061106

1107-
// It("should HExpire", func() {
1108-
// // For testing purposes only
1109-
// client1 := redis.NewClient(&redis.Options{
1110-
// Addr: "localhost:6379",
1111-
// })
1112-
// defer client1.Close()
1113-
1114-
// res, err := client1.HExpire(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
1115-
// Expect(err).To(HaveOccurred())
1116-
// for i := 0; i < 100; i++ {
1117-
// sadd := client1.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1118-
// Expect(sadd.Err()).NotTo(HaveOccurred())
1119-
// }
1120-
1121-
// res, err = client1.HExpire(ctx, "myhash", 10, "key1", "key2", "key200").Result()
1122-
// Expect(err).NotTo(HaveOccurred())
1123-
// Expect(res).To(Equal([]int64{1, 1, -2}))
1124-
// })
1125-
1126-
// It("should HPExpire", func() {
1127-
// // For testing purposes only
1128-
// client1 := redis.NewClient(&redis.Options{
1129-
// Addr: "localhost:6379",
1130-
// })
1131-
// defer client1.Close()
1132-
1133-
// _, err := client1.HPExpire(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
1134-
// Expect(err).To(HaveOccurred())
1135-
// for i := 0; i < 100; i++ {
1136-
// sadd := client1.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1137-
// Expect(sadd.Err()).NotTo(HaveOccurred())
1138-
// }
1139-
1140-
// res, err := client1.HPExpire(ctx, "myhash", 10, "key1", "key2", "key200").Result()
1141-
// Expect(err).NotTo(HaveOccurred())
1142-
// Expect(res).To(Equal([]int64{1, 1, -2}))
1143-
// })
1144-
1145-
// It("should HExpireAt", func() {
1146-
// // For testing purposes only
1147-
// client1 := redis.NewClient(&redis.Options{
1148-
// Addr: "localhost:6379",
1149-
// })
1150-
// defer client1.Close()
1151-
1152-
// _, err := client1.HExpireAt(ctx, "no_such_key", time.Now().Add(10*time.Second), "field1", "field2", "field3").Result()
1153-
// Expect(err).To(HaveOccurred())
1154-
// for i := 0; i < 100; i++ {
1155-
// sadd := client1.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1156-
// Expect(sadd.Err()).NotTo(HaveOccurred())
1157-
// }
1158-
1159-
// res, err := client1.HExpireAt(ctx, "myhash", time.Now().Add(10*time.Second), "key1", "key2", "key200").Result()
1160-
// Expect(err).NotTo(HaveOccurred())
1161-
// Expect(res).To(Equal([]int64{1, 1, -2}))
1162-
// })
1163-
1164-
// It("should HPExpireAt", func() {
1165-
// // For testing purposes only
1166-
// client1 := redis.NewClient(&redis.Options{
1167-
// Addr: "localhost:6379",
1168-
// })
1169-
// defer client1.Close()
1170-
1171-
// _, err := client1.HPExpireAt(ctx, "no_such_key", time.Now().Add(10*time.Second), "field1", "field2", "field3").Result()
1172-
// Expect(err).To(HaveOccurred())
1173-
// for i := 0; i < 100; i++ {
1174-
// sadd := client1.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1175-
// Expect(sadd.Err()).NotTo(HaveOccurred())
1176-
// }
1177-
1178-
// res, err := client1.HPExpireAt(ctx, "myhash", time.Now().Add(10*time.Second), "key1", "key2", "key200").Result()
1179-
// Expect(err).NotTo(HaveOccurred())
1180-
// Expect(res).To(Equal([]int64{1, 1, -2}))
1181-
// })
1182-
1183-
// It("should HPersist", func() {
1184-
// // For testing purposes only
1185-
// client1 := redis.NewClient(&redis.Options{
1186-
// Addr: "localhost:6379",
1187-
// })
1188-
// defer client1.Close()
1189-
1190-
// _, err := client1.HPersist(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
1191-
// Expect(err).To(HaveOccurred())
1192-
// for i := 0; i < 100; i++ {
1193-
// sadd := client1.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1194-
// Expect(sadd.Err()).NotTo(HaveOccurred())
1195-
// }
1196-
1197-
// res, err := client1.HPersist(ctx, "myhash", 10, "key1", "key2", "key200").Result()
1198-
// Expect(err).NotTo(HaveOccurred())
1199-
// Expect(res).To(Equal([]int64{0, 0, -1}))
1200-
1201-
// res, err = client1.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
1202-
// Expect(err).NotTo(HaveOccurred())
1203-
// Expect(res).To(Equal([]int64{1, 1, -2}))
1204-
1205-
// res, err = client1.HPersist(ctx, "myhash", 10, "key1", "key2", "key200").Result()
1206-
// Expect(err).NotTo(HaveOccurred())
1207-
// Expect(res).To(Equal([]int64{1, -1, -2}))
1208-
// })
1209-
1210-
// It("should HExpireTime", func() {
1211-
// // For testing purposes only
1212-
// client1 := redis.NewClient(&redis.Options{
1213-
// Addr: "localhost:6379",
1214-
// })
1215-
// defer client1.Close()
1216-
1217-
// _, err := client1.HExpireTime(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
1218-
// Expect(err).To(HaveOccurred())
1219-
// for i := 0; i < 100; i++ {
1220-
// sadd := client1.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1221-
// Expect(sadd.Err()).NotTo(HaveOccurred())
1222-
// }
1223-
1224-
// res, err := client1.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
1225-
// Expect(err).NotTo(HaveOccurred())
1226-
// Expect(res).To(Equal([]int64{1, -2}))
1227-
1228-
// res, err = client1.HExpireTime(ctx, "myhash", 10, "key1", "key2", "key200").Result()
1229-
// Expect(err).NotTo(HaveOccurred())
1230-
// Expect(res).To(Equal([]int64{1234567890, -1, -2}))
1231-
// })
1232-
1233-
// It("should HPExpireTime", func() {
1234-
// // For testing purposes only
1235-
// client1 := redis.NewClient(&redis.Options{
1236-
// Addr: "localhost:6379",
1237-
// })
1238-
// defer client1.Close()
1239-
1240-
// _, err := client1.HPExpireTime(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
1241-
// Expect(err).To(HaveOccurred())
1242-
// for i := 0; i < 100; i++ {
1243-
// sadd := client1.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1244-
// Expect(sadd.Err()).NotTo(HaveOccurred())
1245-
// }
1246-
1247-
// res, err := client1.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
1248-
// Expect(err).NotTo(HaveOccurred())
1249-
// Expect(res).To(Equal([]int64{1, -2}))
1250-
1251-
// res, err = client1.HPExpireTime(ctx, "myhash", 10, "key1", "key2", "key200").Result()
1252-
// Expect(err).NotTo(HaveOccurred())
1253-
// Expect(res).To(Equal([]int64{1234567890, -1, -2}))
1254-
// })
1255-
1256-
// It("should HTTL", func() {
1257-
// // For testing purposes only
1258-
// client1 := redis.NewClient(&redis.Options{
1259-
// Addr: "localhost:6379",
1260-
// })
1261-
// defer client1.Close()
1262-
1263-
// _, err := client1.HTTL(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
1264-
// Expect(err).To(HaveOccurred())
1265-
// for i := 0; i < 100; i++ {
1266-
// sadd := client1.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1267-
// Expect(sadd.Err()).NotTo(HaveOccurred())
1268-
// }
1269-
1270-
// res, err := client1.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
1271-
// Expect(err).NotTo(HaveOccurred())
1272-
// Expect(res).To(Equal([]int64{1, -2}))
1273-
1274-
// res, err = client1.HTTL(ctx, "myhash", 10, "key1", "key2", "key200").Result()
1275-
// Expect(err).NotTo(HaveOccurred())
1276-
// Expect(res).To(Equal([]int64{10, -1, -2}))
1277-
// })
1278-
1279-
// It("should HPTTL", func() {
1280-
// // For testing purposes only
1281-
// client1 := redis.NewClient(&redis.Options{
1282-
// Addr: "localhost:6379",
1283-
// })
1284-
// defer client1.Close()
1285-
1286-
// _, err := client1.HPTTL(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
1287-
// Expect(err).To(HaveOccurred())
1288-
// for i := 0; i < 100; i++ {
1289-
// sadd := client1.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1290-
// Expect(sadd.Err()).NotTo(HaveOccurred())
1291-
// }
1292-
1293-
// res, err := client1.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
1294-
// Expect(err).NotTo(HaveOccurred())
1295-
// Expect(res).To(Equal([]int64{1, -2}))
1296-
1297-
// res, err = client1.HPTTL(ctx, "myhash", 10, "key1", "key2", "key200").Result()
1298-
// Expect(err).NotTo(HaveOccurred())
1299-
// Expect(res).To(Equal([]int64{10, -1, -2}))
1300-
// })
1107+
It("should HExpire", func() {
1108+
res, err := client.HExpire(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
1109+
Expect(err).To(HaveOccurred())
1110+
for i := 0; i < 100; i++ {
1111+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1112+
Expect(sadd.Err()).NotTo(HaveOccurred())
1113+
}
13011114

1302-
It("should HSetF and HGetF", func() {
1303-
// For testing purposes only
1304-
// client1 := redis.NewClient(&redis.Options{
1305-
// Addr: "localhost:6379",
1306-
// })
1307-
// defer client1.Close()
1115+
res, err = client.HExpire(ctx, "myhash", 10, "key1", "key2", "key200").Result()
1116+
Expect(err).NotTo(HaveOccurred())
1117+
Expect(res).To(Equal([]int64{1, 1, -2}))
1118+
})
1119+
1120+
It("should HPExpire", func() {
1121+
_, err := client.HPExpire(ctx, "no_such_key", 10, "field1", "field2", "field3").Result()
1122+
Expect(err).To(HaveOccurred())
1123+
for i := 0; i < 100; i++ {
1124+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1125+
Expect(sadd.Err()).NotTo(HaveOccurred())
1126+
}
1127+
1128+
res, err := client.HPExpire(ctx, "myhash", 10, "key1", "key2", "key200").Result()
1129+
Expect(err).NotTo(HaveOccurred())
1130+
Expect(res).To(Equal([]int64{1, 1, -2}))
1131+
})
1132+
1133+
It("should HExpireAt", func() {
1134+
_, err := client.HExpireAt(ctx, "no_such_key", time.Now().Add(10*time.Second), "field1", "field2", "field3").Result()
1135+
Expect(err).To(HaveOccurred())
1136+
for i := 0; i < 100; i++ {
1137+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1138+
Expect(sadd.Err()).NotTo(HaveOccurred())
1139+
}
13081140

1141+
res, err := client.HExpireAt(ctx, "myhash", time.Now().Add(10*time.Second), "key1", "key2", "key200").Result()
1142+
Expect(err).NotTo(HaveOccurred())
1143+
Expect(res).To(Equal([]int64{1, 1, -2}))
1144+
})
1145+
1146+
It("should HPExpireAt", func() {
1147+
_, err := client.HPExpireAt(ctx, "no_such_key", time.Now().Add(10*time.Second), "field1", "field2", "field3").Result()
1148+
Expect(err).To(HaveOccurred())
1149+
for i := 0; i < 100; i++ {
1150+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1151+
Expect(sadd.Err()).NotTo(HaveOccurred())
1152+
}
1153+
1154+
res, err := client.HPExpireAt(ctx, "myhash", time.Now().Add(10*time.Second), "key1", "key2", "key200").Result()
1155+
Expect(err).NotTo(HaveOccurred())
1156+
Expect(res).To(Equal([]int64{1, 1, -2}))
1157+
})
1158+
1159+
It("should HPersist", func() {
1160+
_, err := client.HPersist(ctx, "no_such_key", "field1", "field2", "field3").Result()
1161+
Expect(err).To(HaveOccurred())
1162+
for i := 0; i < 100; i++ {
1163+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1164+
Expect(sadd.Err()).NotTo(HaveOccurred())
1165+
}
1166+
1167+
res, err := client.HPersist(ctx, "myhash", "key1", "key2", "key200").Result()
1168+
Expect(err).NotTo(HaveOccurred())
1169+
Expect(res).To(Equal([]int64{-1, -1, -2}))
1170+
1171+
res, err = client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
1172+
Expect(err).NotTo(HaveOccurred())
1173+
Expect(res).To(Equal([]int64{1, -2}))
1174+
1175+
res, err = client.HPersist(ctx, "myhash", "key1", "key2", "key200").Result()
1176+
Expect(err).NotTo(HaveOccurred())
1177+
Expect(res).To(Equal([]int64{1, -1, -2}))
1178+
})
1179+
1180+
It("should HExpireTime", func() {
1181+
_, err := client.HExpireTime(ctx, "no_such_key", "field1", "field2", "field3").Result()
1182+
Expect(err).To(HaveOccurred())
1183+
for i := 0; i < 100; i++ {
1184+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1185+
Expect(sadd.Err()).NotTo(HaveOccurred())
1186+
}
1187+
1188+
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
1189+
Expect(err).NotTo(HaveOccurred())
1190+
Expect(res).To(Equal([]int64{1, -2}))
1191+
1192+
res, err = client.HExpireTime(ctx, "myhash", "key1", "key2", "key200").Result()
1193+
Expect(err).NotTo(HaveOccurred())
1194+
Expect(res[0]).To(BeNumerically("~", time.Now().Add(10*time.Second).Unix(), 1))
1195+
})
1196+
1197+
It("should HPExpireTime", func() {
1198+
_, err := client.HPExpireTime(ctx, "no_such_key", "field1", "field2", "field3").Result()
1199+
Expect(err).To(HaveOccurred())
1200+
for i := 0; i < 100; i++ {
1201+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1202+
Expect(sadd.Err()).NotTo(HaveOccurred())
1203+
}
1204+
1205+
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
1206+
Expect(err).NotTo(HaveOccurred())
1207+
Expect(res).To(Equal([]int64{1, -2}))
1208+
1209+
res, err = client.HPExpireTime(ctx, "myhash", "key1", "key2", "key200").Result()
1210+
Expect(err).NotTo(HaveOccurred())
1211+
Expect(res).To(BeEquivalentTo([]int64{time.Now().Add(10 * time.Second).UnixMilli(), -1, -2}))
1212+
})
1213+
1214+
It("should HTTL", func() {
1215+
_, err := client.HTTL(ctx, "no_such_key", "field1", "field2", "field3").Result()
1216+
Expect(err).To(HaveOccurred())
1217+
for i := 0; i < 100; i++ {
1218+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1219+
Expect(sadd.Err()).NotTo(HaveOccurred())
1220+
}
1221+
1222+
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
1223+
Expect(err).NotTo(HaveOccurred())
1224+
Expect(res).To(Equal([]int64{1, -2}))
1225+
1226+
res, err = client.HTTL(ctx, "myhash", "key1", "key2", "key200").Result()
1227+
Expect(err).NotTo(HaveOccurred())
1228+
Expect(res).To(Equal([]int64{10, -1, -2}))
1229+
})
1230+
1231+
It("should HPTTL", func() {
1232+
_, err := client.HPTTL(ctx, "no_such_key", "field1", "field2", "field3").Result()
1233+
Expect(err).To(HaveOccurred())
1234+
for i := 0; i < 100; i++ {
1235+
sadd := client.HSet(ctx, "myhash", fmt.Sprintf("key%d", i), "hello")
1236+
Expect(sadd.Err()).NotTo(HaveOccurred())
1237+
}
1238+
1239+
res, err := client.HExpire(ctx, "myhash", 10, "key1", "key200").Result()
1240+
Expect(err).NotTo(HaveOccurred())
1241+
Expect(res).To(Equal([]int64{1, -2}))
1242+
1243+
res, err = client.HPTTL(ctx, "myhash", "key1", "key2", "key200").Result()
1244+
Expect(err).NotTo(HaveOccurred())
1245+
Expect(res[0]).To(BeNumerically("~", 10*time.Second.Milliseconds(), 1))
1246+
})
1247+
1248+
It("should HSetF and HGetF", func() {
13091249
sadd := client.HSetF(ctx, "myhash", redis.HSetFArgs{}, "field1", "Hello", "field2", "World")
13101250
Expect(sadd.Err()).NotTo(HaveOccurred())
13111251
Expect(sadd.Val()).To(Equal([]string{"1", "1"}))

0 commit comments

Comments
 (0)