REDIS:
INSTALLATION,
CONFIGURATION &
IMPLEMENTATION
Everything and Anything I.T
By
Abhijeet Shekhar
Installation
Linux: http://redis.io/download
Windows
1. Clone from Git repo:
https://github.com/MSOpenTech/redis
2. Unzip ...
Configuration
 Configuration file: /redis/redis.conf
 It is possible to change a port (if you wish):
 For development e...
Running Redis Server
 Run /redis/bin/redis-server.exe and
specify configuration file to use
redis>redis-server redis.conf
Running Redis Client
 Run /redis/bin/redis-cli.exe
 Now you can play with Redis a little bit
Useful Commands
 Print all keys:
 Remove all keys from all databases
 Synchronously save the dataset to disk
KEYS *
FLU...
Redis keys
 Keys are binary safe - it is possible to use any
binary sequence as a key
 The empty string is also a valid ...
Redis data types
Redis is often referred to as a data structure
server since keys can contain:
 Strings
 Lists
 Sets
 ...
Redis Strings: Example
Redis Lists
 Lists of strings, sorted by insertion order
 Add elements to a Redis List pushing new
elements on the head ...
Redis Lists: Example
Redis Sorted Sets
 Every member of a Sorted Set is associated with
score, that is used in order to take the sorted set
or...
Redis Hashes
 Map between string fields and string values
 Perfect data type to represent objects
HMSET user:1000 userna...
Redis Operations
It is possible to run atomic operations on data
types:
 appending to a string
 incrementing the value i...
Redis client
 PHPRedis – PHP Client for Redis
(https://github.com/nicolasff/phpredis)
 JRedis - Java Client for Redis
 ...
Configuration
By Redis.conf
port 6379
bind 127.0.0.1
maxclients 10000
maxmemory <bytes>
By script
$redis->config("GET", "*...
PHP code
<?php
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->set('key','value', 10); // Will set the k...
Thanks 
Upcoming SlideShare
Loading in …5
×

Redis Installation Configuration And Implementation

1,023 views

Published on

This is basic understanding of Redis. How to install, configure and implement in the PHP

Published in: Software, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,023
On SlideShare
0
From Embeds
0
Number of Embeds
30
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Redis Installation Configuration And Implementation

  1. 1. REDIS: INSTALLATION, CONFIGURATION & IMPLEMENTATION Everything and Anything I.T By Abhijeet Shekhar
  2. 2. Installation Linux: http://redis.io/download Windows 1. Clone from Git repo: https://github.com/MSOpenTech/redis 2. Unzip file from /redis/bin/release (e.g. redisbin64.zip) to /redis 3. Important files:  /redis/redis-server.exe  /redis/redis-cli.exe
  3. 3. Configuration  Configuration file: /redis/redis.conf  It is possible to change a port (if you wish):  For development environment it is useful to change data persisting policy port 6379 save 900 1 save 300 10 save 60 10000 save 10 1 save after 10 sec if at least 1 key changed
  4. 4. Running Redis Server  Run /redis/bin/redis-server.exe and specify configuration file to use redis>redis-server redis.conf
  5. 5. Running Redis Client  Run /redis/bin/redis-cli.exe  Now you can play with Redis a little bit
  6. 6. Useful Commands  Print all keys:  Remove all keys from all databases  Synchronously save the dataset to disk KEYS * FLUSHALL SAVE
  7. 7. Redis keys  Keys are binary safe - it is possible to use any binary sequence as a key  The empty string is also a valid key  Too long keys are not a good idea  Too short keys are often also not a good idea ("u:1000:pwd" versus "user:1000:password")  Nice idea is to use some kind of schema, like: "object-type:id:field"
  8. 8. Redis data types Redis is often referred to as a data structure server since keys can contain:  Strings  Lists  Sets  Hashes  Sorted Sets
  9. 9. Redis Strings: Example
  10. 10. Redis Lists  Lists of strings, sorted by insertion order  Add elements to a Redis List pushing new elements on the head (on the left) or on the tail (on the right) of the list  Max length: (2^32 - 1) elements  Model a timeline in a social network, using LPUSH to add new elements, and using LRANGE in order to retrieve recent items  Use LPUSH together with LTRIM to create a list that never exceeds a given number of elements
  11. 11. Redis Lists: Example
  12. 12. Redis Sorted Sets  Every member of a Sorted Set is associated with score, that is used in order to take the sorted set ordered, from the smallest to the greatest score  You can do a lot of tasks with great performance that are really hard to model in other kind of databases  Probably the most advanced Redis data type
  13. 13. Redis Hashes  Map between string fields and string values  Perfect data type to represent objects HMSET user:1000 username abhi password 123 age 28 HGETALL user:1000 HSET user:1000 password 12345 HGETALL user:1000
  14. 14. Redis Operations It is possible to run atomic operations on data types:  appending to a string  incrementing the value in a hash  pushing to a list  computing set intersection, union and difference  getting the member with highest ranking in a sorted set
  15. 15. Redis client  PHPRedis – PHP Client for Redis (https://github.com/nicolasff/phpredis)  JRedis - Java Client for Redis  Jedis - a blazingly small and sane Redis Java client  Spring Data Redis
  16. 16. Configuration By Redis.conf port 6379 bind 127.0.0.1 maxclients 10000 maxmemory <bytes> By script $redis->config("GET", "*max-*-entries*"); $redis->config("SET", "dir", "/var/run/redis/dumps/");
  17. 17. PHP code <?php $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $redis->set('key','value', 10); // Will set the key, if it doesn't exist, with a ttl of 10 seconds echo $redis->get(‘key’); ?>
  18. 18. Thanks 

×