Skip to main content

Posts

Design Patterns (aka DP), Creational - Factory Pattern

DP is a well-described solution to a common software problem. Its benefits: Already defined to solve a problem. Increase code reusability and robustness. Faster devlopment and new developers in team can understand it easily DP defined in to 3 categories: Creational  - Used to construct objects such that they can be decoupled from their implementing system. Structural  - Used to form large object structures between many disparate objects Behavioral  - Used to manage algorithms, relationships, and responsibilities between objects. Creational : Factory  - Exposes a method for creating objects, allowing sub-classes to control the actual creation process. Consider a scenario as below:- You have an interface or abstract class or a normal class. Computer class There are 2 sub-classes of of Computer. PC class and Server class Now you have a factory which provides you Computers. And you can give specification to factory whether you want a PC or Server. Below

Design Patterns (aka DP), Creational - Singleton Pattern

DP is a well-described solution to a common software problem. Its benefits: Already defined to solve a problem. Increase code reusability and robustness. Faster devlopment and new developers in team can understand it easily DP defined in to 3 categories: Creational  - Used to construct objects such that they can be decoupled from their implementing system. Structural  - Used to form large object structures between many disparate objects Behavioral  - Used to manage algorithms, relationships, and responsibilities between objects. Creational : Singleton - Singleton pattern restricts the instantiation of a class and ensures that only one instance of the class exists in the jvm. We have different approaches for Singleton but all of these follow below bullets: Private constructor Private static variable of same class i.e. only instance of class. Public static method of class that returns the instance. A few points to think about before implementation: Y

Redis- Data Types

There are 5 types of data types: Strings: Redis string is a sequence of bytes. Strings in Redis are binary safe, having fixed length, So, one can store anything up to 512 megabytes in one string. 127.0.0.1:6379> SET name "Dinesh Sachdev" OK 127.0.0.1:6379> get name "Dinesh Sachdev" Hashes: It is a collection of key value pairs. Every hash can store up to 232 - 1 field-value pairs (more than 4 billion). 127.0.0.1:6379> HMSET user:1 username dineshSachdev password dinesh123 address 123 OK 127.0.0.1:6379> HGETALL user:1 1) "username" 2) "dineshSachdev" 3) "password" 4) "dinesh123" 5) "address" 6) "123" 127.0.0.1:6379> HGET user:1 username "dineshSachdev" 127.0.0.1:6379> HGET user:1 password "dinesh123" Lists: Redis Lists are simply lists of strings, sorted by insertion order. You can add elements to a Redis List on the head or on the tail. 127.

Install and Use Redis

Redis is an open source, BSD licensed, advanced key-value store. Redis holds its database entirely in memory, using the disk only for persistence. Redis can replicate data to any number of slaves. Installing Redis Download the latest stable release tarball or wget http://download.redis.io/releases/redis-stable.tar.gz Untar it:            tar xzf redis-stable.tar.gz Change Directory or make entry to '.bashrc':           cd redis-stable Proceed to with the make command:           make Run the recommended make test:           make test Start Redis hduser@slave:~$ redis-server 8413:C 02 Feb 13:29:24.587 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf 8413:M 02 Feb 13:29:24.591 # You requested maxclients of 10000 requiring at least 10032 max file descriptors. 8413:M 02 Feb 13:29:24.592 # Redis can't set maximum open files to 10032 because of OS err