示例#1
0
        public void RedisStorageStoresAndRetrievesComplexObjectsInBulks()
        {
            var objectToStore = new ComplexParameter()
            {
                SomeProperty = "this is string",
                AnotherProperty = 47
            };
            KeyValuePair<string, ComplexParameter>[] objectsToStore = new KeyValuePair<string, ComplexParameter>[100];
            for (int i = 0; i < objectsToStore.Length; i++)
            {
                objectsToStore[i] = new KeyValuePair<string, ComplexParameter>(Guid.NewGuid().ToString(), objectToStore);
            }

            using (var storage = new RedisStorage(RedisStorageTests.Host))
            {
                storage.BulkStore(objectsToStore);
                var retrievedObjects = storage.BulkRetrieve<ComplexParameter>(objectsToStore.Select(o => o.Key).ToArray());

                foreach (var retrievedObject in retrievedObjects)
                {
                    retrievedObject.SomeProperty.ShouldBe(objectToStore.SomeProperty);
                    retrievedObject.AnotherProperty.ShouldBe(objectToStore.AnotherProperty);
                }
            }
        }