Tuesday, 10 January 2017

Redis PHP Interview questions and answers

Redis php interview questions and answers

Question: What is Redis?
Redis is an advanced key-value data store and cache. It has is also referred to as a data structure server as such the keys not only contains strings, but also hashes, sets, lists.


Question: What are the advantages of using Redis?
  1. It provides high speed
  2. It has got command level Atomic Operation (tx operation)
  3. It supports a server-side locking
  4. It has got lots of client lib



Question: What are the limitations of Redis?
  1. It is single threaded
  2. It has got limited client support
  3. It is not deployed



Question: Why Redis is different as compared to other key-value stores?
  1. Redis values can contain more complex data types, with atomic operations.
  2. Redis is an in-memory but persistent on disk database.



Question: How to delete current database?
redis-cli flushdb



Question: How to remove all database?
redis-cli flushall



Question: How to check redis is running?
try {
    $redis = new Redis();
    $redis->connect('127.0.0.1', 6379);
    echo "Redis is running.";
    echo "Server is running: " . $redis->ping();
} catch (Exception $e) {
    echo $e->getMessage();
}



Question: How to set value in redis?
$redis->set("name", "Set string in redis");



Question: How to get value from redis?
 echo $redis->get('name'); //Set string in redis



Question: How to set multiple values (Array) in redis?
$redis->lpush("tutorials", "PHP");
$redis->lpush("tutorials", "MySQL");
$redis->lpush("tutorials", "Redis");
$redis->lpush("tutorials", "Mongodb");
$redis->lpush("tutorials", "Mysql");



Question: How to get array data from redis?
$list = $redis->lrange("tutorials", 0 ,5);   
print_r($list);
/*Array ( [0] => Mysql [1] => Mongodb [2] => Redis [3] => MySQL [4] => PHP [5] => Mysql ) */
Question: How to get all keys from redis?
$keyList = $redis->keys("*");
print_r($keyList);
/*Array ( [0] => tutorials [1] => name ) */
Question: How to stop redis?
/etc/init.d/redis-server stop



Question: How to start redis?
/etc/init.d/redis-server start



Question: How to re-start redis?
/etc/init.d/redis-server restart



Question: How do I move a redis database from one server to another?
  1. use BGSAVE command to Save a spanshot of the database into a dump.rdb
  2. Copy this dump.rdb file into another server.

Monday, 9 January 2017

How to integrate Google Places Search API in website?

How to integrate Google Places Search API in website?

Get the Google API Key
  1. Login to https://console.developers.google.com
  2. Get the API Keys.
  3. Enable "Google Places API Web Service" from Google Google Map API



HTML Code

<script src="https://maps.googleapis.com/maps/api/js?v=3&amp;libraries=places&amp;key=HERE_YOUR_KEYS"></script>
<div class="search-Form">
<input id="search" name="q" type="text" value="" /> <input id="submit" type="submit" value="go" />
</div>



JavaScript Code

    var lat
    var lon
    function initialize() {
        var input = document.getElementById('search');
        var autocomplete = new google.maps.places.Autocomplete(input);

        google.maps.event.addListener(autocomplete, 'place_changed', function() {
            var place = autocomplete.getPlace();
            lat = place.geometry.location.lat()
            lon = place.geometry.location.lng()
        });

    }

    google.maps.event.addDomListener(window, 'load', initialize);

View Demo