Interface IDistributedHashSet<T>
This interface contains methods and parameters for Distributed HashSet.
Inherited Members
Assembly: Alachisoft.NCache.Client.dll
Syntax
public interface IDistributedHashSet<T> : ICollection<T>, IEnumerable<T>, IEnumerable, IDistributedDataTypes, ILockable, INotifiable
Type Parameters
Name | Description |
---|---|
T | The type of the elements in the HashSet. |
Methods
AddRange(IEnumerable<T>)
Insert elements of the provided collection in IDistributedSet.
Declaration
void AddRange(IEnumerable<T> collection)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | collection | Elements to be inserted in the IDistributedSet. |
Examples
The following code sample shows how to add multiple items in a Distributed Set.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string dataTypeName = "DistributedSet";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet>int>(dataTypeName);
// Create array of userIDs
int[] userIDs = new int[3] { 1223, 3564, 4545 };
set.AddRange(userIDs);
Difference(String)
Returns the difference of current Set with the specified Set.
Declaration
IEnumerable<T> Difference(string other)
Parameters
Type | Name | Description |
---|---|---|
System.String | other | Name of Set to compare with. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | Difference of current Set with the specified Set. |
Examples
The following code sample shows how to get difference of a Set with another Set.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string MondayUsersKey = "MondayUsers";
string TuesdayUsersKey = "TuesdayUsers";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet<int>(TuesdayUsersKey);
// Set of MondayUsers already exists in cache.
IEnumerable<int> result = set.Difference(MondayUsers);
GetRandom()
Returns a random element from the Set.
Declaration
T GetRandom()
Returns
Type | Description |
---|---|
T | Random element from the Set. |
Examples
The following code sample shows how to get random element from Distributed Set.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string dataTypeName = "DistributedSet";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet<int>(dataTypeName);
int result = set.GetRandom();
GetRandom(Int32)
Returns count distinct random elements from the Set.
Declaration
T[] GetRandom(int count)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | count | Number of required elements. |
Returns
Type | Description |
---|---|
T[] | Count distinct elements from the Set. |
Examples
The following code sample shows how to get random elements from a Distributed Set.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string dataTypeName = "DistributedSet";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet<int>(dataTypeName);
int[] result = set.GetRandom(5);
Intersect(String)
Returns the intersection of current Set with the specified Set.
Declaration
IEnumerable<T> Intersect(string other)
Parameters
Type | Name | Description |
---|---|---|
System.String | other | Name of Set to compare with. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | Intersection of current Set with the specified Set. |
Examples
The following code sample shows how to get intersection of a Set with another Set.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string MondayUsersKey = "MondayUsers";
string TuesdayUsersKey = "TuesdayUsers";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet<int>(TuesdayUsersKey);
// Set of MondayUsers already exists in cache.
IEnumerable<int> result = set.Intersect(MondayUsers);
Remove(ICollection<T>)
Remove the specified items from the Set.
Declaration
int Remove(ICollection<T> items)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.ICollection<T> | items | Items to remove from the Set. |
Returns
Type | Description |
---|---|
System.Int32 | The number of members that were removed from the Set. |
Examples
The following code sample shows how to remove specified element from Distributed Set.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string dataTypeName = "DistributedSet";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet<int>(dataTypeName);
// Creating ID to remove from set.
ICollection<int> ids = GetExpiredIDs();
int count = set.Remove(ids);
RemoveRandom()
Removes and returns a random element from the Set.
Declaration
T RemoveRandom()
Returns
Type | Description |
---|---|
T | Random element from the Set. |
Examples
The following code sample shows how to remove random element from a Distributed Set.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string dataTypeName = "DistributedSet";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet>int>(dataTypeName);
int result = set.RemoveRandom();
StoreDifference(String, String)
Take difference of current Set with the specified Set and store the result in a new destination Set.
Declaration
IDistributedHashSet<T> StoreDifference(string destination, string other)
Parameters
Type | Name | Description |
---|---|---|
System.String | destination | Name of a destination Set. |
System.String | other | Name of the Set to compare with. |
Returns
Type | Description |
---|---|
IDistributedHashSet<T> | Interface of destination Set handler. |
Examples
The following code sample shows how to get difference of a Set with another Set and store the result in cache.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string MondayUsersKey = "MondayUsers";
string TuesdayUsersKey = "TuesdayUsers";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet<int>(TuesdayUsersKey);
string differenceSet = "DifferenceSet";
// Set of MondayUsers already exists in cache.
IDistributedHashSet<int> result = set.StoreDifference(differenceSet, MondayUsersKey);
StoreIntersection(String, String)
Take intersection of current Set with the specified Set and store the result in a new destination Set.
Declaration
IDistributedHashSet<T> StoreIntersection(string destination, string other)
Parameters
Type | Name | Description |
---|---|---|
System.String | destination | Name of a destination Set. |
System.String | other | Name of the Set to compare with. |
Returns
Type | Description |
---|---|
IDistributedHashSet<T> | Interface of destination Set handler. |
Examples
The following code sample shows how to get intersection of a Set with another Set and store the result in cache.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string MondayUsersKey = "MondayUsers";
string TuesdayUsersKey = "TuesdayUsers";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet<int>(TuesdayUsersKey);
string intersectionSet = "IntersectionSet";
// Set of MondayUsers already exists in cache.
IDistributedHashSet<int> result = set.StoreDifference(intersectionSet, MondayUsersKey);
StoreUnion(String, String)
Take union of current Set with the specified Set and store the result in a new destination Set.
Declaration
IDistributedHashSet<T> StoreUnion(string destination, string other)
Parameters
Type | Name | Description |
---|---|---|
System.String | destination | Name of destination Set. |
System.String | other | Name of Set to compare with. |
Returns
Type | Description |
---|---|
IDistributedHashSet<T> | Interface of destination Set handler. |
Examples
The following code sample shows how to get union of a Set with another Set and store the result in the cache.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string MondayUsersKey = "MondayUsers";
string TuesdayUsersKey = "TuesdayUsers";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet<int>(TuesdayUsersKey);
string unionSet = "UnionSet";
// Set of MondayUsers already exists in cache.
IDistributedHashSet<int> result = set.StoreUnion(unionSet, MondayUsersKey);
Union(String)
Returns the union of the current Set with the specified Set.
Declaration
IEnumerable<T> Union(string other)
Parameters
Type | Name | Description |
---|---|---|
System.String | other | Name of Set to compare with. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | Union of current Set with the specified Set. |
Examples
The following code sample shows how to get union of a Set with another Set.
ICache cache = CacheManager.GetCache("demoClusteredCache");
string MondayUsersKey = "MondayUsers";
string TuesdayUsersKey = "TuesdayUsers";
IDistributedHashSet<int> set = cache.DataTypeManager.GetHashSet<int>(TuesdayUsersKey);
// Set of MondayUsers already exists in cache.
IEnumerable<int> result = set.Union(MondayUsers);