Original address: http://blog.fens.me/linux-redis-install/
Installing Redis in Ubuntu
The R Sword NoSQL series article focuses on using the NoSQL database with the R language connection. The NoSQL products involved, including Redis, MongoDB, HBase, Hive, Cassandra, neo4j. I hope that through my introduction to the vast number of R language enthusiasts, there are more development options, to make more exciting applications.
About
- Zhang Dan (Conan), programmer Java,r,php,javascript
- Weibo: @Conan_Z
- Blog:http://blog.fens.me
- Email: [Email protected]
Reprint please specify the source:
http://blog.fens.me/linux-redis-install/
Objective
Redis is a common memory-based Key-value database that is more advanced than memcache and supports a variety of data structures, efficiently and quickly. Redis makes it easy to solve high-concurrency data access problems, and it is also very good to monitor signal processing at all times.
Directory
- Redis installs in Windows
- Redis installs in Linux Ubuntu
- Accessing Redis from a command-line client
- Modifying the configuration of Redis
1. Redis installation in Windows
Installing a Redis database on a Windows system is a simple matter, download the executable installation file (EXE), and double-click the installation. : Https://github.com/rgl/redis/downloads
- Redis Server Run command: Redis installation directory/redis-server.exe
- Redis Client Run command: Redis installation directory/redis-cli.exe
2. Redis installed in Linux Ubuntu
The Linux used in this article is an Ubuntu 12.04.2 LTS 64bit system, and the installation of the Redis database package can be implemented through Apt-get.
Installing the Redis database in Linux Ubuntu
#安装Redis服务器端~ sudo apt-get install redis-server
After the installation is complete, the Redis server starts automatically and we check the Redis server program
# 检查Redis服务器系统进程~ ps -aux|grep redisredis 4162 0.1 0.0 10676 1420 ? Ss 23:24 0:00 /usr/bin/redis-server /etc/redis/redis.confconan 4172 0.0 0.0 11064 924 pts/0 S+ 23:26 0:00 grep --color=auto redis# 通过启动命令检查Redis服务器状态~ netstat -nlt|grep 6379tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN# 通过启动命令检查Redis服务器状态~ sudo /etc/init.d/redis-server statusredis-server is running
3. Accessing Redis from a command-line client
Installing the Redis server will automatically install the Redis command-line client program together.
The native Input redis-cli command can be started, and the client program accesses the Redis server.
~ redis-cliredis 127.0.0.1:6379># 命令行的帮助redis 127.0.0.1:6379> helpredis-cli 2.2.12Type: "help @" to get a list of commands in "help " for help on "help " to get a list of possible help topics "quit" to exit# 查看所有的key列表redis 127.0.0.1:6379> keys *(empty list or set)
Basic Redis Client Command operations
Add a string record Key1
# 增加一条记录key1redis 127.0.0.1:6379> set key1 "hello"OK# 打印记录redis 127.0.0.1:6379> get key1"hello"
Add a digital record Key2
# 增加一条数字记录key2set key2 1OK# 让数字自增redis 127.0.0.1:6379> INCR key2(integer) 2redis 127.0.0.1:6379> INCR key2(integer) 3# 打印记录redis 127.0.0.1:6379> get key2"3"
Add a list record Key3
# 增加一个列表记录key3redis 127.0.0.1:6379> LPUSH key3 a(integer) 1# 从左边插入列表redis 127.0.0.1:6379> LPUSH key3 b(integer) 2# 从右边插入列表redis 127.0.0.1:6379> RPUSH key3 c(integer) 3# 打印列表记录,按从左到右的顺序redis 127.0.0.1:6379> LRANGE key3 0 31) "b"2) "a"3) "c"
Add a hash table record Key4
# 增加一个哈希记表录key4redis 127.0.0.1:6379> HSET key4 name "John Smith"(integer) 1# 在哈希表中插入,email的Key和Value的值redis 127.0.0.1:6379> HSET key4 email "[email protected]"(integer) 1# 打印哈希表中,name为key的值redis 127.0.0.1:6379> HGET key4 name"John Smith"# 打印整个哈希表redis 127.0.0.1:6379> HGETALL key41) "name"2) "John Smith"3) "email"4) "[email protected]"
Add a hash table record Key5
# 增加一条哈希表记录key5,一次插入多个Key和value的值redis 127.0.0.1:6379> HMSET key5 username antirez password P1pp0 age 3OK# 打印哈希表中,username和age为key的值redis 127.0.0.1:6379> HMGET key5 username age1) "antirez"2) "3"# 打印完整的哈希表记录redis 127.0.0.1:6379> HGETALL key51) "username"2) "antirez"3) "password"4) "P1pp0"5) "age"6) "3"
Deleting records
# 查看所有的key列表redis 127.0.0.1:6379> keys *1) "key2"2) "key3"3) "key4"4) "key5"5) "key1"# 删除key1,key5redis 127.0.0.1:6379> del key1(integer) 1redis 127.0.0.1:6379> del key5(integer) 1# 查看所有的key列表redis 127.0.0.1:6379> keys *1) "key2"2) "key3"3) "key4"
4. Modify the Redis configuration
4.1 Accessing your account using Redis
By default, access to the Redis server does not require a password, and for added security we need to set the access password for the Redis server. Set the access password to Redisredis.
Open the configuration file for Redis server with VI redis.conf
~ sudo vi /etc/redis/redis.conf#取消注释requirepassrequirepass redisredis
4.2 Let Redis server be accessed remotely
By default, the Redis server does not allow remote access and allows only native access, so we need to set the ability to turn on remote access.
Open the configuration file for Redis server with VI redis.conf
~ sudo vi /etc/redis/redis.conf#注释bind#bind 127.0.0.1
After modification, restart the Redis server.
~ sudo /etc/init.d/redis-server restartStopping redis-server: redis-server.Starting redis-server: redis-server.
Login to Redis server with no password
~ redis-cliredis 127.0.0.1:6379> keys *(error) ERR operation not permitted
Found to be able to log on, but could not execute command.
Login to Redis server and enter your password
~ redis-cli -a redisredisredis 127.0.0.1:6379> keys *1) "key2"2) "key3"3) "key4"
After landing, everything is fine.
We check Redis's network listening port
检查Redis服务器占用端口~ netstat -nlt|grep 6379tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN
We saw from the network monitoring from 127.0.0.1:3306 to 0 0.0.0.0:3306, which means that Redis has allowed remote login access.
We access the Redis server from another Linux remote
~ redis-cli -a redisredis -h 192.168.1.199redis 192.168.1.199:6379> keys *1) "key2"2) "key3"3) "key4"
Remote access is OK. With the above operation, we will install the Redis database server in Linux Ubuntu system.
Reprint please specify the source:
http://blog.fens.me/linux-redis-install/
This entry is posted in operating system, database
Installing Redis in Ubuntu