Redis is an open-source key-value database, which is characterized by storing data based on key values;
It is also often considered a data structure server. Because its value includes not only the basic string type but also the List,set, sorted set and hash type.
Redis website Address: https://redis.io/
Redis Service Files:
RPM-QL redis# View file information generated after Redis installation, such as configuration files, log files, and service files/etc/redis.conf# the service file/usr/bin/redis-server#redis the main profile/usr/bin/ redis-sentinel# is used when configuring master-slave replication and high availability, Sentinel also has its own service unit file and configuration file/usr/lib/systemd/system/redis.service# start Redis unit File/var/lib/redis#redis the directory in which data is stored on disk, although Redis is based on memory data structures, it still has IO operations on the disk/var/run/redis# the Redis runtime PID information/var/log/redis #存放redis日志的
Turn on Redis Services
Systemctl start Redis.service Ss-ntl#redis default listener for TCP 6379 ports on 127.0.0.1
Client Tools for Redis: REDIS-CLI
redis-cli-h# View the Help information for this client tool redis-cli# connect to the native Redis directly by entering this command
Default database for Redis
[[Email protected] ~] #redis-cli 127.0.0.1:6379> Select 15ok127.0.0.1:6379[15]> Select (Error) ERR invalid DB Inde X#redis default has 16 databases, numbering, range is 0-15, default login to 0 database # switch Library keyword Select
Redis supports a variety of data structures, so the operation is different
127.0.0.1:6379[15]> Help [Tab|tab tab] #redis的help功能做的很好, different data types can find helpful information
Below we demonstrate how to use it according to different data structures.
String type data:127.0.0.1:6379[15]> set key1 ' Hello redis ' ok127.0.0.1:6379[15]> get key1 "Hello redis" #简单创建一个字符串的键值127 .0.0.1:6379[15]> append key1 ', Hello linux ' (integer) 23127.0.0.1:6379[15]> get key1 "Hello redis,hello linux" #追加字符串127.0.0.1 : 6379[15]> strlen key1 (integer) 23# string length 127.0.0.1:6379[15]> incr count (integer) 1127.0.0.1:6379[15]> incr count (integer) 2127.0.0.1:6379[15]> incr count ( Integer) 3127.0.0.1:6379[15]> incrby count 2 (integer) 5127.0.0.1:6379[15]> decr count (integer) 4127.0.0.1:6379[15]> decrby count 3 (integer) 1# INCR and DECR are respectively added to the value of one or minus one, Incrby and Decrby respectively is to add or subtract the value of the specified step number 127.0.0.1:6379[15]> get count "1" 127.0.0.1:6379[15]> del count (integer) 1127.0.0.1:6379[15]> get count (nil) #删除键
list type data: 127.0.0.1:6379[15]> lpush number one two three four (integer) 4127.0.0.1:6379[15]> lindex number 0 "four" 127.0.0.1:6379 [15]> lindex number 3 "One" 127.0.0.1:6379[15]> linsert number after One zero (integer) 5127.0.0.1:6379[15]> lindex number 3 "one" 127.0.0.1:6379[15]> lindex number 4 "Zero" 127.0.0.1:6379[15]> lrange number 0 41) "Four "2) " three "3) " 4 " " one "5) " Zero "#LPUSH是从左向右入栈, Rpush is right-to-left into the stack, Linsert is to insert a value from left to right, Lrange is the parameter range that displays the specified key 127.0.0.1:6379[15]> rpop number "zero" 127.0.0.1:6379[15]> llen Number (integer) 3#rpop is a right-to-left pop-up field, Lpop is a left-to-right pop-up field, Llen is a list of the lengths of the specified key
Hash data type:127.0.0.1:6379[15]> Hmset member name Tom Age gender maleok# primary key and sub-key 127.0.0.1:6379[15]> hgetall member1) " Name "2)" Tom "3)" age "4)" 5 "[Gender] 6)" Male "#显示所有键值127 .0.0.1:6379[15]> hkeys member1)" name "2)" age "3)" Gender "# Show only sub-keys 127.0.0.1:6379[15]> hvals member1) "Tom" 2) "3" "Male" #显示子键值127 .0.0.1:6379[15]> Hstrlen member age ( Integer) 2127.0.0.1:6379[15]> Hdel member Gender (integer) 1
The above shows the basic operation of a variety of data types under the Redis interface, you can refer to help to continue learning
This article shows the end of this
This article from "A_pan" blog, declined reprint!
--redis Foundation of non-relational database