Hazelcast .NET Client

Elastically scale your .NET application against real-time data extensive requirements with modern asynchronous APIs. Hazelcast is an excellent solution when scaling and speed matter.

  • Access all of the Hazelcast data structures plus distributed queues, topics, and more with the Hazelcast .NET Client
  • Use SQL to run queries over your distributed data.
  • Use the Hazelcast Near Cache feature to store frequently read data in your .NET application. Near Cache provides faster read speeds than traditional caches such as Redis or Memcached. Eventual Consistency is also supported.
  • Provides SSL support and Mutual Authentication for your enterprise-level security needs.
  • Use and query your JSON objects.
  • Zero downtime during upgrades with Blue/Green failover support.
  • Cluster wide synchronization capability with distributed locks powered by CP Subsystem.

Quick Start + Download

Quick Start

From NuGet package manager console: Install-Package Hazelcast.Net

Downloads

Version Downloads Documentation
Hazelcast IMDG .NET/CSharp Client 5.3.1 (latest)
10/04/2023
Hazelcast IMDG .NET/CSharp Client 5.3.0
06/23/2023
Hazelcast IMDG .NET/CSharp Client 5.2.2
05/29/2023
Hazelcast IMDG .NET/CSharp Client 5.2.1
04/01/2023

For all downloads please see the Download Archives

Previous Releases

Code Samples

  1. using System.Threading.Tasks;
  2.  
  3. namespace Hazelcast.Examples.WebSite
  4. {
  5. // ReSharper disable once UnusedMember.Global
  6. public class MapExample
  7. {
  8. public static async Task Main(string[] args)
  9. {
  10. var options = new HazelcastOptionsBuilder()
  11. .With(args)
  12. .WithConsoleLogger()
  13. .Build();
  14.  
  15. // create an Hazelcast client and connect to a server running on localhost
  16. await using var client = await HazelcastClientFactory.StartNewClientAsync(options);
  17.  
  18. // get distributed map from cluster
  19. await using var map = await client.GetMapAsync<string, string>("my-distributed-map");
  20.  
  21. // set/get
  22. await map.SetAsync("key", "value");
  23. await map.GetAsync("key");
  24.  
  25. // concurrent methods, optimistic updating
  26. await map.PutIfAbsentAsync("somekey", "somevalue");
  27. await map.ReplaceAsync("key", "value", "newvalue");
  28.  
  29. // destroy the map
  30. await client.DestroyAsync(map);
  31. }
  32. }
  33. }
View Sample on GitHub
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. namespace Hazelcast.Examples.WebSite
  5. {
  6. // ReSharper disable once UnusedMember.Global
  7. public class QueueExample
  8. {
  9. public static async Task Main(string[] args)
  10. {
  11. var options = new HazelcastOptionsBuilder()
  12. .With(args)
  13. .WithConsoleLogger()
  14. .Build();
  15.  
  16. // create an Hazelcast client and connect to a server running on localhost
  17. await using var client = await HazelcastClientFactory.StartNewClientAsync(options);
  18.  
  19. // Get a Blocking Queue called "my-distributed-queue"
  20. var queue = await client.GetQueueAsync<string>("my-distributed-queue");
  21. // Offer a String into the Distributed Queue
  22. await queue.PutAsync("item");
  23. // Poll the Distributed Queue and return the String
  24. await queue.PollAsync();
  25. //Timed blocking Operations
  26. await queue.OfferAsync("anotheritem", TimeSpan.FromMilliseconds(500));
  27. await queue.PollAsync(TimeSpan.FromSeconds(5));
  28. //Indefinitely blocking Operations
  29. await queue.PutAsync("yetanotheritem");
  30. Console.WriteLine(await queue.TakeAsync());
  31. }
  32. }
  33. }
View Sample on GitHub
  1. using System;
  2. using System.Threading.Tasks;
  3. using Hazelcast.DistributedObjects;
  4.  
  5. namespace Hazelcast.Examples.WebSite
  6. {
  7. // ReSharper disable once UnusedMember.Global
  8. public class TopicExample
  9. {
  10. private static void OnMessage(IHTopic<string> sender, TopicMessageEventArgs<string> args)
  11. {
  12. Console.WriteLine($"Got message " + args.Payload);
  13. }
  14.  
  15. public static async Task Main(string[] args)
  16. {
  17. var options = new HazelcastOptionsBuilder()
  18. .With(args)
  19. .WithConsoleLogger()
  20. .Build();
  21.  
  22. // create an Hazelcast client and connect to a server running on localhost
  23. await using var client = await HazelcastClientFactory.StartNewClientAsync(options);
  24.  
  25. // get distributed topic from cluster
  26. await using var topic = await client.GetTopicAsync<string>("my-distributed-topic");
  27.  
  28. // subscribe to event
  29. await topic.SubscribeAsync(on => on.Message(OnMessage));
  30.  
  31. // publish a message to the Topic
  32. await topic.PublishAsync("Hello to distributed world");
  33.  
  34. // allow event to trigger
  35. await Task.Delay(1_000);
  36.  
  37. // destroy the topic
  38. await client.DestroyAsync(topic);
  39. }
  40. }
  41. }
View Sample on GitHub
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. namespace Hazelcast.Examples.WebSite
  5. {
  6. // ReSharper disable once UnusedMember.Global
  7. public class ListExample
  8. {
  9. public static async Task Main(string[] args)
  10. {
  11. var options = new HazelcastOptionsBuilder()
  12. .With(args)
  13. .WithConsoleLogger()
  14. .Build();
  15.  
  16. // create an Hazelcast client and connect to a server running on localhost
  17. await using var client = await HazelcastClientFactory.StartNewClientAsync(options);
  18.  
  19. // Get the Distributed List from Cluster.
  20. await using var list = await client.GetListAsync<string>("my-distributed-list");
  21.  
  22. // Add elements to the list
  23. await list.AddAsync("item1");
  24. await list.AddAsync("item2");
  25.  
  26. // Remove the first element
  27. Console.WriteLine("Removed: " + await list.RemoveAsync(0));
  28. // There is only one element left
  29. Console.WriteLine("Current size is " + await list.GetSizeAsync());
  30. // Clear the list
  31. await list.ClearAsync();
  32.  
  33. await client.DestroyAsync(list);
  34. }
  35. }
  36. }
View Sample on GitHub
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. namespace Hazelcast.Examples.WebSite
  5. {
  6. // ReSharper disable once UnusedMember.Global
  7. public class ReplicatedMapExample
  8. {
  9. public static async Task Main(string[] args)
  10. {
  11. var options = new HazelcastOptionsBuilder()
  12. .With(args)
  13. .WithConsoleLogger()
  14. .Build();
  15.  
  16. // create an Hazelcast client and connect to a server running on localhost
  17. await using var client = await HazelcastClientFactory.StartNewClientAsync(options);
  18.  
  19. // Get a Replicated Map called "my-replicated-map"
  20. await using var map = await client.GetReplicatedMapAsync<string, string>("my-replicated-map");
  21. // Put and Get a value from the Replicated Map
  22. var replacedValue = await map.PutAsync("key", "value"); // key/value replicated to all members
  23. Console.WriteLine("replacedValue = " + replacedValue); // Will be null as its first update
  24. var value = await map.GetAsync("key"); // the value is retrieved from a random member in the cluster
  25. Console.WriteLine("value for key = " + value);
  26. }
  27. }
  28. }
View Sample on GitHub
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. namespace Hazelcast.Examples.WebSite
  5. {
  6. // ReSharper disable once UnusedMember.Global
  7. public class SetExample
  8. {
  9. public static async Task Main(string[] args)
  10. {
  11. var options = new HazelcastOptionsBuilder()
  12. .With(args)
  13. .WithConsoleLogger()
  14. .Build();
  15.  
  16. // create an Hazelcast client and connect to a server running on localhost
  17. await using var client = await HazelcastClientFactory.StartNewClientAsync(options);
  18.  
  19. // Get the Distributed Set from Cluster.
  20. await using var set = await client.GetSetAsync<string>("my-distributed-set");
  21.  
  22. // Add items to the set with duplicates
  23. await set.AddAsync("item1");
  24. await set.AddAsync("item1");
  25. await set.AddAsync("item2");
  26. await set.AddAsync("item2");
  27. await set.AddAsync("item2");
  28. await set.AddAsync("item3");
  29.  
  30. // Get the items. Note that there are no duplicates.
  31. await foreach (var item in set)
  32. {
  33. Console.WriteLine(item);
  34. }
  35.  
  36. await client.DestroyAsync(set);
  37. }
  38. }
  39. }
View Sample on GitHub
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. namespace Hazelcast.Examples.WebSite
  5. {
  6. // ReSharper disable once UnusedMember.Global
  7. public class MultiMapExample : ExampleBase
  8. {
  9. public async Task Run(string[] args)
  10. {
  11. // create an Hazelcast client and connect to a server running on localhost
  12. await using var client = await HazelcastClientFactory.StartNewClientAsync(BuildExampleOptions(args));
  13.  
  14. // Get the Distributed MultiMap from Cluster.
  15. await using var multiMap = await client.GetMultiMapAsync("my-distributed-multimap");
  16. // Put values in the map against the same key
  17. await multiMap.PutAsync("my-key", "value1");
  18. await multiMap.PutAsync("my-key", "value2");
  19. await multiMap.PutAsync("my-key", "value3");
  20. // Print out all the values for associated with key called "my-key"
  21. var values = await multiMap.GetAsync("my-key");
  22. foreach (var item in values)
  23. {
  24. Console.WriteLine(item);
  25. }
  26.  
  27. // remove specific key/value pair
  28. await multiMap.RemoveAsync("my-key", "value2");
  29. }
  30. }
  31. }
View Sample on GitHub
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. namespace Hazelcast.Examples.WebSite
  5. {
  6. // ReSharper disable once UnusedMember.Global
  7. public class RingBufferExample
  8. {
  9. public static async Task Main(string[] args)
  10. {
  11. var options = new HazelcastOptionsBuilder()
  12. .With(args)
  13. .WithConsoleLogger()
  14. .Build();
  15.  
  16. // create an Hazelcast client and connect to a server running on localhost
  17. await using var client = await HazelcastClientFactory.StartNewClientAsync(options);
  18.  
  19. await using var rb = await client.GetRingBufferAsync<long>("rb");
  20.  
  21. // add two items into ring buffer
  22. await rb.AddAsync(100);
  23. await rb.AddAsync(200);
  24.  
  25. // we start from the oldest item.
  26. // if you want to start from the next item, call rb.tailSequence()+1
  27. var sequence = await rb.GetHeadSequenceAsync();
  28. Console.WriteLine(await rb.ReadOneAsync(sequence));
  29. sequence += 1;
  30. Console.WriteLine(await rb.ReadOneAsync(sequence));
  31.  
  32. await client.DestroyAsync(rb);
  33. }
  34. }
  35. }
View Sample on GitHub