Skip to content

Commit e82c8c3

Browse files
committed
Populate items in all redis data types + add to db 1
1 parent c94a22c commit e82c8c3

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed
Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using RedisAdminUI.DataSource.Northwind;
33
using RedisAdminUI.ServiceModel.Operations.App;
4+
using ServiceStack;
45
using ServiceStack.Redis;
56

67
namespace RedisAdminUI.ServiceInterface.App
@@ -21,32 +22,47 @@ public object Any(PopulateRedisWithData request)
2122
Redis.StoreAll(NorthwindData.Orders);
2223
Redis.StoreAll(NorthwindData.Products);
2324
Redis.StoreAll(NorthwindData.OrderDetails);
24-
//Redis.StoreAll(NorthwindData.CustomerCustomerDemos);
2525
Redis.StoreAll(NorthwindData.Regions);
2626
Redis.StoreAll(NorthwindData.Territories);
2727
Redis.StoreAll(NorthwindData.EmployeeTerritories);
2828

2929
LoadDifferentKeyTypes(Redis);
3030

31+
//Just load collections in DB 1
32+
using (var redisDb1 = new RedisClient(Redis.Host, Redis.Port, db: 1))
33+
{
34+
LoadDifferentKeyTypes(redisDb1);
35+
}
36+
3137
return new PopulateRedisWithDataResponse();
3238
}
3339

34-
protected void LoadDifferentKeyTypes(IRedisClient client)
40+
protected void LoadDifferentKeyTypes(IRedisClient redis)
3541
{
36-
var items = new List<string> { "one", "two", "three", "four" };
37-
var map = new Dictionary<string, string> {
38-
{"A","one"},
39-
{"B","two"},
40-
{"C","three"},
41-
{"D","four"},
42-
};
43-
44-
items.ForEach(x => Redis.Set("urn:testkeytypes:string:" + x, x));
45-
items.ForEach(x => Redis.AddItemToList("urn:testkeytypes:list", x));
46-
items.ForEach(x => Redis.AddItemToSet("urn:testkeytypes:set", x));
47-
var i = 0;
48-
items.ForEach(x => Redis.AddItemToSortedSet("urn:testkeytypes:zset", x, i++));
49-
Redis.SetRangeInHash("urn:testkeytypes:hash", map);
42+
int A = 'A';
43+
int Z = 'Z';
44+
var letters = (Z - A + 1).Times(i => ((char)(i + A)).ToString());
45+
var numbers = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
46+
47+
var pos = 0;
48+
letters.Each(x => redis.Set("string:letters/" + x, x));
49+
numbers.Each(x => redis.Set("string:numbers/" + pos++, x));
50+
51+
letters.Each(x => redis.AddItemToList("list:letters", x));
52+
numbers.Each(x => redis.AddItemToList("list:numbers", x));
53+
54+
letters.Each(x => redis.AddItemToSet("set:letters", x));
55+
numbers.Each(x => redis.AddItemToSet("set:numbers", x));
56+
57+
pos = 0;
58+
letters.Each(x => redis.AddItemToSortedSet("zset:letters", x, pos++));
59+
pos = 0;
60+
numbers.Each(x => redis.AddItemToSortedSet("zset:numbers", x, pos++));
61+
62+
pos = 0;
63+
letters.Each(x => redis.SetEntryInHash("hash:letters", x, (pos++).ToString()));
64+
pos = 0;
65+
numbers.Each(x => redis.SetEntryInHash("hash:numbers", x, (pos++).ToString()));
5066
}
5167
}
5268
}

0 commit comments

Comments
 (0)