NOSQL Basic Knowledge
Nosql: key-value
Redis: one kind of nosql. Data cachs in Memory, regular write into disk.
Used in:
1. Get the latest N record
2. Get the top N record
3. Set expired date of record
4. Get unique data
5. Real time system
....
redis vs mysql vs mongdb
mysql: database; table; column
mongodb: database; aggregation;no column
redis: database; no table; no column
Redis Installation
1. Download from redis.io http://redis.io/download
2. unzip the package: tar xvf redis-3.0.2.tar.gz
3. install package: make MALLOC=libc
4. move the /tmp/redis-3.0.2 to /usr/local/redis
5. set path: vim /etc/profile.d/redis.sh
export PATH=/usr/local/redis/src:$PATH
6. change config file vim /usr/local/redis/redis.conf
A. Change from
daemonize no
to
daemonize yes
B. Change from
logfile ""
to
logfile "/var/log/redis/redis.log"
7. set service: vim /etc/rc.d/init.d/redis
#!/bin/bash
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/redis/src/redis-server
CLIEXEC=/usr/local/redis/src/redis-cli
CONF="/usr/local/redis/redis.conf"
case "$1" in
start)
echo "Starting Redis server..."
$EXEC $CONF > /dev/null&
;;
stop)
echo "Stopping ..."
$CLIEXEC shutdown
echo "Redis stopped"
;;
restart)
echo "Stopping ..."
$CLIEXEC shutdown
echo "Redis stopped"
echo "Starting Redis server..."
$EXEC $CONF > /dev/null &
;;
*)
echo "Please use start or stop or restart as first argument"
;;
esac
8. Add to chkconfig: chkconfig --add redis
9. Start redis: service redis start
MongoDB Installation
1. Download Mongodb package https://www.mongodb.org/downloads
2. unzip the package: tar zxvf mongodb-linux-x86_64-rhel62-3.0.4.tgz
2. unzip the package: tar zxvf mongodb-linux-x86_64-rhel62-3.0.4.tgz
3. move package: mv /tmp/mongodb-linux-x86_64-rhel62-3.0.4 /usr/local/mongodb
4. set path: vim /etc/profile.d/mongodb.sh
export PATH=/usr/local/mongodb/bin:$PATH
5. create config file: vim /usr/local/mongodb/bin/mongodb.conf
dbpath=/data/db
logpath=/var/log/mongodb/mongodb.log
port=27017
fork=true
nohttpinterface=true
6. create folders:
data folder: mkdir -p /data/db
log folder: mkdir -p /var/log/mongodb
7. start mongodb: mongod -f /usr/local/mongodb/bin/mongodb.conf
8. login mongodb command line: mongo
9. check databases: show databases;
10. check collection: show collections;
11. check table: show tables;
12. check table records: select * from <table name>;
13. check collection records: <collection name>.find();
13. create database: use <database name>;
14. create collection:
i. db.user.save({name:'Rod',age:30})
ii. for(var i=1;i<=10; i++) db.user.save({x:8;y:i})
Redis Gui Tool: Redis Desktop Manger
Mongodb Gui Tool: NoSQL Manager for MongoDB Professional
Comments
Post a Comment