Installing Redis in Ubuntu

Source: Internet
Author: User
Tags install redis redis server

1.apt-get Install Redis-server

2. 检查Redis服务器系统进程 ~ ps -aux|grep redis

redis 4162 0.1 0.0 10676 1420 ? Ss 23:24 0:00 /usr/bin/redis-server

/etc/redis/redis.conf conan 4172 0.0 0.0 11064 924 pts/0 S+ 23:26 0:00 grep --color=auto redis

3.通过启动命令检查Redis服务器状态 ~ netstat -nlt|grep 6379

tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN

4.通过启动命令检查Redis服务器状态 ~ sudo /etc/init.d/redis-server status

redis-server is running

When installing Redis-server, the client commands are installed together, so you can use REDIS-CLI to enter the client

~ redis-Cliredis127.0.0.1:6379># command-line help Redis127.0.0.1:6379>Helpredis-cli2.2. AType:"Help @"To get a list of commandsinch       " Help"  for Help on" Help"To get a list of possible Help topics"quit"to exit# View all key list Redis127.0.0.1:6379> Keys *(empty list or set)

Test:

127.0.0.1:6379> Keys *(empty list or set)127.0.0.1:6379> Set Key"My name is Yuwensong"; Invalid argument (s)127.0.0.1:6379> Set Key"My name is Yuwensong"OK127.0.0.1:6379> Key *(Error) ERR unknown command'Key'127.0.0.1:6379> Keys *1)"Key"127.0.0.1:6379>Get key"My name is Yuwensong"127.0.0.1:6379>
 # adds a digital record key2set key2  1  ok# let the number self-increment redis  127.0 . 0.1 : 6379  >  INCR key2 (integer)  2  redis  127.0 . 0.1 : 6379  >  INCR key2 (integer)  3  # Print Records Redis  127.0 . 0.1 : 6379  >  get Key2   " 3   
# Add a list record Key3redis127.0.0.1:6379>lpush Key3 A (integer)1# Insert List from left Redis127.0.0.1:6379>lpush Key3 B (integer)2# Insert List from right Redis127.0.0.1:6379>rpush key3 C (integer)3# Print List records, by left-to-right in the order of Redis127.0.0.1:6379> Lrange Key30 31)"b"2)"a"3)"C"
# Add a hash record Key4redis127.0.0.1:6379> Hset key4 Name"John Smith"(integer)1# Insert in hash table, email key and value Redis127.0.0.1:6379> Hset key4 Email"[email protected]"(integer)1# Print Hash table, name is the value of key Redis127.0.0.1:6379>hget Key4 name"John Smith"# Print entire hash table Redis127.0.0.1:6379>Hgetall Key41)"name"2)"John Smith"3)"Email"4)"[email protected]"
Add a hash table record key5# add a hash table record KEY5, insert multiple keys and value at once Redis127.0.0.1:6379> hmset key5 username antirez Password P1pp0 age3ok# print hash table, username and the value of age key Redis127.0.0.1:6379>hmget key5 username age1)"Antirez"2)"3"# Print full hash table record for Redis127.0.0.1:6379>Hgetall Key51)"username"2)"Antirez"3)"Password"4)"p1pp0"5)" Age"6)"3"

Delete a record # View all key list Redis127.0.0.1:6379> Keys *1)"Key2"2)"Key3"3)"Key4"4)"Key5"5)"Key1"# Delete Key1,key5redis127.0.0.1:6379>del key1 (integer)1Redis127.0.0.1:6379>del key5 (integer)1# View all key list Redis127.0.0.1:6379> Keys *1)"Key2"2)"Key3"3)"Key4"
4. Modifying the configuration of Redis4.1access accounts using Redis by default, access to the Redis server is not required, 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# Uncomment Requirepassrequirepass Redisredis4.2make Redis server remote access 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# Comment Bind#bind127.0.0.1after modification, restart the Redis server. ~sudo/etc/init.d/redis-Server restartstopping Redis-server:redis-server. Starting Redis-server:redis-server. Log in to Redis server without using a password~ redis-Cliredis127.0.0.1:6379> Keys *(Error) ERR operation not permitted found to be able to login, but could not execute command. Login to Redis server and enter your password~ REDIS-CLI-a Redisredisredis127.0.0.1:6379> Keys *1)"Key2"2)"Key3"3)"Key4"after landing, everything is fine. 
We check Redis's network listening port to check Redis server occupancy Port~ netstat-nlt|grep 6379TCP0      0 0.0.0.0:6379            0.0.0.0:*Listen we see from between the network listening from127.0.0.1:3306Become0 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-h192.168.1.199Redis192.168.1.199:6379> Keys *1)"Key2"2)"Key3"3)"Key4"remote access is OK. Through the above operation, we will be the Redis database server, Linux ubuntu system installation completed

Installing Redis in Ubuntu

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.