For the RedisSetService class, see the encapsulation in Article 1

The use of redis data structure Set

using (RedisSetService service = new RedisSetService())
{
service.FlushAll();// Clear all data

service.Add("advanced"."111");
service.Add("advanced"."112");
service.Add("advanced"."114");
service.Add("advanced"."114");
service.Add("advanced"."115");
service.Add("advanced"."115");
service.Add("advanced"."113");

var result = service.GetAllItemsFromSet("advanced");

var random = service.GetRandomItemFromSet("advanced");// Random fetch
service.GetCount("advanced");// Number of independent IP addresses
service.RemoveItemFromSet("advanced"."114");

{
service.Add("begin"."111");
service.Add("begin"."112");
service.Add("begin"."115");

service.Add("end"."111");
service.Add("end"."114");
service.Add("end"."113");

var result1 = service.GetIntersectFromSets("begin"."end");
var result2 = service.GetDifferencesFromSet("begin"."end");
var result3 = service.GetUnionFromSets("begin"."end"); }}Copy the code

case

// De-weight: de-weight IP statistics; Add a friend request; Voting restrictions; Thumb up.
// The use of cross
using (RedisSetService service = new RedisSetService())
{
service.FlushAll();// Clear all data
service.Add("XT"."Powell");
service.Add("XT"."Tenk");
service.Add("XT"."spider");
service.Add("XT"."spider");
service.Add("XT"."spider");
service.Add("XT"."aaron");
service.Add("XT"."Linsan");

service.Add("Powell"."Eleven");
service.Add("Powell"."Tenk");
service.Add("Powell"."ywa");
service.Add("Powell"."Pang");
service.Add("Powell"."Jeff");

var result = service.GetIntersectFromSets("XT"."Powell");
var result2 = service.GetDifferencesFromSet("Powell"."XT");
var result3 = service.GetDifferencesFromSet("XT"."Powell");
var result4=service.GetUnionFromSets("XT"."Powell");
}
Copy the code
/// <summary>
///Friend management Mutual friends - may know
///Find mutual friends:
///Relational databases: Find two lists of friends and compare them
///Secondary friends (possible acquaintance) :
/// 
///Since it is using Redis, use the Api encapsulated in Redis as much as possible;
/// </summary>
public static void Show()
{ 
    using (RedisSetService service = new RedisSetService())
    { 
        service.FlushAll();
        service.Add("xut"."Cloud bosom");
        service.Add("xut"."fresh");
        service.Add("xut"."Teng kun");
        service.Add("xut"."The heart belongs.");
        service.Add("xut"."Shakespeare");

        service.Add("fresh"."Ollie to.");
        service.Add("fresh"."Dreams of Tomorrow");
        service.Add("fresh"."Lollipop");
        service.Add("fresh"."Put down");
        service.Add("fresh"."Wechat in the Sun");
        service.Add("fresh"."Teng kun");
        //1. Query common friends; masked
        var resut1 = service.GetIntersectFromSets("xut"."fresh");//
        //2. Recommend by a friend/maybe know someone
        var resut2 = service.GetDifferencesFromSet("fresh"."xut");//
        var resut3 = service.GetDifferencesFromSet("xut"."fresh");//

        var result4 = service.GetUnionFromSets("xut"."fresh"); }}Copy the code

Extended edition

using (RedisSetService service = new RedisSetService())
                {
                    //key--values
                    service.KeyFulsh();
                    service.Add("Advanced"."111");
                    service.Add("Advanced"."112");
                    service.Add("Advanced"."113");
                    service.Add("Advanced"."115");
                    service.Add("Advanced"."114");
                    service.Add("Advanced"."111");

                    service.Add("Begin"."111");
                    service.Add("Begin"."112");
                    service.Add("Begin"."113");
                    service.Add("Begin"."117");
                    service.Add("Begin"."116");
                    service.Add("Begin"."111");

                    service.Add("Internal"."111");
                    service.Add("Internal"."112");
                    service.Add("Internal"."117");
                    service.Add("Internal"."119");
                    service.Add("Internal"."118");
                    service.Add("Internal"."111");

                    var result = service.GetAllItemsFromSet("Advanced");
                    var result2 = service.GetRandomItemFromSet("Advanced");
                    result = service.GetAllItemsFromSet("Begin");
                    result2 = service.GetRandomItemFromSet("Begin");

                    var result3 = service.GetIntersectFromSets("Advanced"."Begin");/ / /
                    result3 = service.GetDifferencesFromSet("Advanced"."Begin"."Internal");/ / poor
                    result3 = service.GetUnionFromSets("Advanced"."Begin"."Internal");/ / and

                    service.RemoveItemFromSet("Advanced"."111");
                    result = service.GetAllItemsFromSet("Advanced");
                    service.RandomRemoveItemFromSet("Advanced");
                    result = service.GetAllItemsFromSet("Advanced");
                }
Copy the code