Ubuntu used on Redis Database storage SessionID and implementation Session shared
First part: Installation and configuration Redis Database
installation Redis database server. See also:http://grainier.net/how-to-install-redis-in-ubuntu/
Redis official website: https://redis.io/
$ wget http://download.redis.io/releases/redis-3.2.8.tar.gz
$ tar xzf redis-3.2.8.tar.gz
$ CD redis-3.2.8
$ make
$ make Test
$ cat/sys/kernel/mm/transparent_hugepage/enabled// display current THP enabled status
$ sudo su switches to root and then # echo never >/sys/kernel/mm/transparent_hugepage/enabled toggle THP State. Can add it to your/etc/rc.local on order to retain the setting after a reboot.
$ sudo make install// Copy the compiled executable file to the appropriate place to complete the installation.
The Redis main file functions as follows:
Redis-server:daemon boot program for Redis server
REDIS-CLI:Redis Command-line Operations tool. Of course, you can also use telnet to operate on its plain text protocol.
Redis-benchmark:redis Performance testing tool to test the read and write performance of Redis in your system and in your configuration
Redis-stat:redis Status Detection Tool to detect Redis current status parameters and delay status
Use Help:
$ CD Utils
$ sudo./install_server.sh
set the appropriate parameters ( You can change the default port6379 to another value, such as 6535).
port:6535
Config File:/etc/redis/6535.conf
Log File:/var/log/redis_6535.log
Data dir:/var/lib/redis/6535
Executable:/usr/local/bin/redis-server
Cli executable:/USR/LOCAL/BIN/REDIS-CLI
command to use:
$ sudo service redis_6535 start
$ sudo service redis_6535 stop
$ sudo service redis_6535 restart
$ redis-server--help
Connect via client Redis Server:
$ redis-cli-p 6535// login
$ select 1// Select Database
$ keys *// list all keys
$ get key_name// Get value
Redius security settings:https://www.digitalocean.com/community/tutorials/ how-to-secure-your-redis-installation-on-ubuntu-14-04
Part II: Website Code ( placed in server-side main file www.js)
var session= require (' express-session '),
redisstore= require (' Connect-redis ') (session),// UseRedisDatabase StorageSessionInformation
redis= require ("Redis"),// Use Radis Client Node_redis
//================ set Redis database storage share session==================
rsclient= redis.createclient ({// create redis Client Instance
Host: ' 127.0.0.1 ',
port:6535,
db:1});
//==============Setsession (This article should be placed inPassportbefore)==============
Varsessionmiddleware = Session ({
store:new redisstore ({client:rsclient}),// setting willSessionstored inRedisdatabase Inside
Secret: ' Putyoursecrethere ',// Encrypt string , ' Putyoursecrethere ' can be changed to another string
Resave:true,
Saveuninitialized:true
});
Use Redis database storage SessionID on Ubuntu and implement session sharing