public void SetRangeInHash <TKey>(IRedisHash <TKey, T> hash, IEnumerable <KeyValuePair <TKey, T> > keyValuePairs) { var stringKeyValuePairs = keyValuePairs.ToList().ConvertAll( x => new KeyValuePair <string, string>(x.Key.SerializeToString(), x.Value.SerializeToString())); client.SetRangeInHash(hash.Id, stringKeyValuePairs); }
private static void ProcessUserCommand(IRedisHash <String, String> collection) { string command = Console.ReadLine(); if (command == "-show") { ListAllWords(collection); } else if (command == "-add") { Console.WriteLine("Please type word and meaning separated by - !"); string[] parameters = Console.ReadLine().Split('-'); Add(collection, parameters); ListAllWords(collection); } else if (command == "-search") { Console.WriteLine("Please type word."); string parameter = Console.ReadLine(); var foundWord = Find(collection, parameter); Console.WriteLine(foundWord); ListAllWords(collection); } else { Console.WriteLine("Unknown command !"); } }
public void Try_simulate_NRE_when_calling_GetAllEntriesFromHash_using_BasicRedisClientManager() { using (var redisManager = new BasicRedisClientManager(TestConfig.SingleHost)) using (var redis = redisManager.GetClient()) { IRedisHash <string, Test> testHash = redis.As <Test>() .GetHash <string>("test-hash"); Assert.That(testHash.Count, Is.EqualTo(0)); var contents = testHash.GetAll(); Assert.That(contents.Count, Is.EqualTo(0)); var test1 = new Test { Id = 1, Name = "Name1" }; var test2 = new Test { Id = 2, Name = "Name2" }; testHash["A"] = test1; testHash["B"] = test2; contents = testHash.GetAll(); Assert.That(contents, Is.EqualTo(new Dictionary <string, Test> { ["A"] = test1, ["B"] = test2, })); Assert.That(testHash["A"], Is.EqualTo(test1)); Assert.That(testHash["B"], Is.EqualTo(test2)); } }
static void Add(IRedisHash <String, String> collection, string[] parameters) { string word = parameters[0].Trim(); string description = parameters[1].Trim(); collection.Add(word, description); }
static String Find(IRedisHash <String, String> collection, string parameter) { var dictEntry = collection[parameter.Trim()]; if (dictEntry == null) { dictEntry = "Not Found !"; } return(dictEntry); }
public RedisHashTests() { Startup.Run(); _appCache = AppServiceLocator.Current.GetInstance <IAppCache>(); _userRedisHash = AppServiceLocator.Current.GetInstance <IRedisHash <UserInfo> >(); _userRedisHash.FlattenDictionaries = true; // This isn't truly necessary since the default value of PromaryEntityId is a method that uses reflection to // look for a property with a name of Id, UserInfoId, or EntityId; _userRedisHash.PrimaryEntityIdLocator = info => info.Id.ToString(); }
public void Dispose() { redisHash = null; redisKey = null; redisList = null; redisLock = null; redisSet = null; redisSortedSet = null; redisStore = null; redisString = null; redisSubscribe = null; }
static void Main(string[] args) { PooledRedisClientManager pool = new PooledRedisClientManager("[email protected]:10333"); RedisClient redis = (RedisClient)pool.GetClient(); var client = redis.As <string>(); IRedisHash <String, String> hash = client.GetHash <string>("hashID"); while (true) { PrintMenu(); ProcessUserCommand(hash); } }
static void ListAllWords(IRedisHash <String, String> collection) { var dict = collection.GetAll(); Console.WriteLine("----------------------------"); Console.WriteLine("Words in Dictionary:"); Console.WriteLine("----------------------------"); foreach (var entry in dict) { Console.WriteLine(entry.Key + ": " + entry.Value); } ; Console.WriteLine("----------------------------"); }
public void SetUp() { if (client != null) { client.Dispose(); client = null; } client = new RedisClient(TestConfig.SingleHost); client.FlushAll(); redis = client.As <T>(); Hash = redis.GetHash <string>(HashId); }
public SubMapBinder GetSubMapBinder(long globalid) { AssertInitialized(); using (var client = m_clientManager.GetClient()) { IRedisHash <long, SubMapBinder> hash = client.As <SubMapBinder>().GetHash <long>(REDIS_KEY); if (!hash.ContainsKey(globalid)) { throw new Exception(string.Format("Submap {0} not found", globalid)); } return(hash[globalid]); } }
private static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.Console() .CreateLogger(); var serviceProvider = new ServiceCollection() .AddSingleton <IRedisClientsManager>(new RedisManagerPool("localhost:6379")) .BuildServiceProvider(); var clientsManager = serviceProvider .GetService <IRedisClientsManager>(); ExamplesForString.Run(clientsManager); ExamplesForIncrement.Run(clientsManager); ExamplesForHashes.Run(clientsManager); ExamplesForLists.Run(clientsManager); ExamplesForSets.Run(clientsManager); ExamplesForSortedSets.Run(clientsManager); using (var redis = clientsManager.GetClient()) { var redisUsers = redis.As <User>(); var user = new User { Id = Guid.NewGuid().ToString(), Email = "[email protected]", City = "Oslo", Name = "Bob" }; redisUsers.SetValue(user.Id, user); var redisUsersLookup = redis.As <string>(); IRedisHash <string, string> hash = redisUsersLookup.GetHash <string>("user:lookup"); redisUsersLookup.SetEntryInHash(hash, user.Email, user.Id); string userId = redisUsersLookup.GetValueFromHash(hash, user.Email); var storedUser = redisUsers.GetValue(userId); } }
public SubMapBinder[] GetMapSubMapsBinder(int mapid) { AssertInitialized(); using (IRedisClient client = m_clientManager.GetClient()) { IRedisTypedClient <long[]> keysClient = client.As <long[]>(); IRedisHash <int, long[]> hash = keysClient.GetHash <int>(REDIS_MAPS); if (!hash.ContainsKey(mapid)) { return(new SubMapBinder[0]); } long[] submaps = hash[mapid]; var submapClient = (RedisTypedClient <SubMapBinder>)client.As <SubMapBinder>(); return(submapClient.GetValuesFromHash(submapClient.GetHash <long>(REDIS_KEY), submaps).ToArray()); } }
/// <inheritdoc /> public List <TKey> GetHashKeys <TKey>(IRedisHash <TKey, T> hash) { return(ConvertEachTo <TKey>(this._client.GetHashKeys(hash.Id))); }
public override void SetUp() { base.SetUp(); this._redis = this.Redis.As <T>(); this._hash = this._redis.GetHash <string>(_hashId); }
public List <T> GetHashValues <TKey>(IRedisHash <TKey, T> hash) { return(client.GetHashValues(hash.Id).ConvertEachTo <T>()); }
public bool RemoveEntryFromHash <TKey>(IRedisHash <TKey, T> hash, TKey key) { return(client.RemoveEntryFromHash(hash.Id, key.SerializeToString())); }
public bool HashContainsEntry <TKey>(IRedisHash <TKey, T> hash, TKey key) { return(client.HashContainsEntry(hash.Id, key.SerializeToString())); }
public List <T> GetValuesFromHash <TKey>(IRedisHash <TKey, T> hash, params TKey[] keys) { return(client.GetValuesFromHash(hash.Id, keys.Select(x => x.SerializeToString()).ToArray()).ConvertEachTo <T>()); }
public bool SetEntryInHashIfNotExists <TKey>(IRedisHash <TKey, T> hash, TKey key, T value) { return(client.SetEntryInHashIfNotExists(hash.Id, key.SerializeToString(), value.SerializeToString())); }
/// <inheritdoc /> public bool HashContainsEntry <TKey>(IRedisHash <TKey, T> hash, TKey key) { return(this._client.HashContainsEntry(hash.Id, key.ToJson())); }
public T GetValueFromHash <TKey>(IRedisHash <TKey, T> hash, TKey key) { return(DeserializeFromString( client.GetValueFromHash(hash.Id, key.SerializeToString()))); }
/// <inheritdoc /> public bool SetEntryInHashIfNotExists <TKey>(IRedisHash <TKey, T> hash, TKey key, T value) { return(this._client.SetEntryInHashIfNotExists(hash.Id, key.ToJson(), value.ToJson())); }
public long GetHashCount <TKey>(IRedisHash <TKey, T> hash) { return(client.GetHashCount(hash.Id)); }
/// <inheritdoc /> public T GetValueFromHash <TKey>(IRedisHash <TKey, T> hash, TKey key) { return(DeserializeFromString(this._client.GetValueFromHash(hash.Id, key.ToJson()))); }
public Dictionary <TKey, T> GetAllEntriesFromHash <TKey>(IRedisHash <TKey, T> hash) { return(ConvertEachTo <TKey, T>(client.GetAllEntriesFromHash(hash.Id))); }
/// <inheritdoc /> public bool RemoveEntryFromHash <TKey>(IRedisHash <TKey, T> hash, TKey key) { return(this._client.RemoveEntryFromHash(hash.Id, key.ToJson())); }