Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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 !");
            }
        }
Ejemplo n.º 3
0
        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));
                }
        }
Ejemplo n.º 4
0
        static void Add(IRedisHash <String, String> collection, string[] parameters)
        {
            string word        = parameters[0].Trim();
            string description = parameters[1].Trim();

            collection.Add(word, description);
        }
Ejemplo n.º 5
0
        static String Find(IRedisHash <String, String> collection, string parameter)
        {
            var dictEntry = collection[parameter.Trim()];

            if (dictEntry == null)
            {
                dictEntry = "Not Found !";
            }

            return(dictEntry);
        }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
0
 public void Dispose()
 {
     redisHash      = null;
     redisKey       = null;
     redisList      = null;
     redisLock      = null;
     redisSet       = null;
     redisSortedSet = null;
     redisStore     = null;
     redisString    = null;
     redisSubscribe = null;
 }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 11
0
        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]);
            }
        }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
0
        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());
            }
        }
Ejemplo n.º 14
0
 /// <inheritdoc />
 public List <TKey> GetHashKeys <TKey>(IRedisHash <TKey, T> hash)
 {
     return(ConvertEachTo <TKey>(this._client.GetHashKeys(hash.Id)));
 }
Ejemplo n.º 15
0
 public override void SetUp()
 {
     base.SetUp();
     this._redis = this.Redis.As <T>();
     this._hash  = this._redis.GetHash <string>(_hashId);
 }
Ejemplo n.º 16
0
 public List <T> GetHashValues <TKey>(IRedisHash <TKey, T> hash)
 {
     return(client.GetHashValues(hash.Id).ConvertEachTo <T>());
 }
Ejemplo n.º 17
0
 public bool RemoveEntryFromHash <TKey>(IRedisHash <TKey, T> hash, TKey key)
 {
     return(client.RemoveEntryFromHash(hash.Id, key.SerializeToString()));
 }
Ejemplo n.º 18
0
 public bool HashContainsEntry <TKey>(IRedisHash <TKey, T> hash, TKey key)
 {
     return(client.HashContainsEntry(hash.Id, key.SerializeToString()));
 }
Ejemplo n.º 19
0
 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>());
 }
Ejemplo n.º 20
0
 public bool SetEntryInHashIfNotExists <TKey>(IRedisHash <TKey, T> hash, TKey key, T value)
 {
     return(client.SetEntryInHashIfNotExists(hash.Id, key.SerializeToString(), value.SerializeToString()));
 }
Ejemplo n.º 21
0
 /// <inheritdoc />
 public bool HashContainsEntry <TKey>(IRedisHash <TKey, T> hash, TKey key)
 {
     return(this._client.HashContainsEntry(hash.Id, key.ToJson()));
 }
Ejemplo n.º 22
0
 public T GetValueFromHash <TKey>(IRedisHash <TKey, T> hash, TKey key)
 {
     return(DeserializeFromString(
                client.GetValueFromHash(hash.Id, key.SerializeToString())));
 }
Ejemplo n.º 23
0
 /// <inheritdoc />
 public bool SetEntryInHashIfNotExists <TKey>(IRedisHash <TKey, T> hash, TKey key, T value)
 {
     return(this._client.SetEntryInHashIfNotExists(hash.Id, key.ToJson(), value.ToJson()));
 }
Ejemplo n.º 24
0
 public long GetHashCount <TKey>(IRedisHash <TKey, T> hash)
 {
     return(client.GetHashCount(hash.Id));
 }
Ejemplo n.º 25
0
 /// <inheritdoc />
 public T GetValueFromHash <TKey>(IRedisHash <TKey, T> hash, TKey key)
 {
     return(DeserializeFromString(this._client.GetValueFromHash(hash.Id, key.ToJson())));
 }
Ejemplo n.º 26
0
 public Dictionary <TKey, T> GetAllEntriesFromHash <TKey>(IRedisHash <TKey, T> hash)
 {
     return(ConvertEachTo <TKey, T>(client.GetAllEntriesFromHash(hash.Id)));
 }
Ejemplo n.º 27
0
 /// <inheritdoc />
 public bool RemoveEntryFromHash <TKey>(IRedisHash <TKey, T> hash, TKey key)
 {
     return(this._client.RemoveEntryFromHash(hash.Id, key.ToJson()));
 }