Key-value Type Store Database--redis

Source: Internet
Author: User
Tags redis version redis server


1. Introduction


Redis is a fully open source ANSI C language written, compliant with BSD protocol, high-performance Key-value database .


1.1 Features
    • Redis supports data persistence, which saves data in memory on disk and can be loaded again for use when restarting.
    • Redis not only supports simple key-value types of data, but also provides storage of data structures such as List,set,zset,hash.
    • Redis supports backup of data, that is, Master-slave mode of data backup.
1.2 Advantages
    • The performance is very high –redis can read the speed is 110,000 times/s, the write speed is 81,000 times/s.
    • Rich data types –redis support binary case Strings, Lists, hashes, sets and Ordered sets data type operations.
    • Atomic –redis All operations are atomic, meaning either successful execution or failure to execute at all. A single operation is atomic. Multiple operations also support transactions, namely atomicity, wrapped by multi and EXEC commands.
2. Install the 2.1windows installation


Download the Redis-x64-3.2.100.zip under Https://github.com/MicrosoftArchive/redis/releases.






Move the downloaded package to the C drive, create a new Redis folder, and unzip the compressed package under the Redis folder.



Open a cmd window using the CD command to switch directories to C:\redis run redis-server.exe redis.windows.conf .


C:\redis> redis-server.exe redis.windows.conf
                _._
           _.-``__ ‘‘-._
      _.-``    `.  `_.  ‘‘-._           Redis 3.2.100 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ‘‘-._
 (    ‘      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|‘` _.-‘|     Port: 6379
 |    `-._   `._    /     _.-‘    |     PID: 11604
  `-._    `-._  `-./  _.-‘    _.-‘
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|
 |    `-._`-._        _.-‘_.-‘    |           http://redis.io
  `-._    `-._`-.__.-‘_.-‘    _.-‘
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|
 |    `-._`-._        _.-‘_.-‘    |
  `-._    `-._`-.__.-‘_.-‘    _.-‘
      `-._    `-.__.-‘    _.-‘
          `-._        _.-‘
              `-.__.-‘

[11604] 24 Nov 11:04:00.253 # Server started, Redis version 3.2.100


At this time another cmd window, the original do not close, otherwise you will not be able to access the server.



Switch to the Redis directory to run the redis-cli.exe-h 127.0.0.1-p 6379 .



Set the key-value pair set MyKey ABC



Remove key value pair get MyKey


 
C:\redis>redis-cli.exe -h 127.0.0.1 -p 6379
127.0.0.1:6379> set mykey yaohong
OK
127.0.0.1:6379> get mykey
"yaohong"
127.0.0.1:6379>
3. Configuration


3.1 Getting the configuration


#CONFIG GET *


3.2 Convenient Configuration


" Notice "
4. Data type


Redis supports five types of data: String (String), hash (hash), list, set (set), and Zset (sorted set: Ordered set).


5. Command 5.1 basic commands


Start the Redis client


c:\redis>redis-CLI127.0. 0.1:6379>


Detects if the Redis service is started


127.0. 0.1:6379>  PINGPONG


Connect remote


127.0. 0.1 6379 " Mypass "
127.0. 0.1:6379>127.0. 0.1:6379> PING
5.2 Keys (key)


add: SET keyname redis---key followed by Key's name and key value



Delete: del keyname



change: EXPIRE yhkey--- change the expiration time of key, EXPIRE in seconds, pexpire in milliseconds



TTL myname-----Change key never Expires



Rename Key Yhkey9



Check: Keys * query all keys



Keys yh* filters out keys that contain YH



exists KeyName determine if key exists



Pttl Mekey Find the time remaining for key


5.3redis-string
#increase
127.0.0.1:6379> SET keyname2 "hello myname is yaohong, what is your name?"
OK
#check
127.0.0.1:6379> GET keyname2
"hello myname is yaohong, what is your name?"


#Intercept string
127.0.0.1:6379> GETRANGE keyname2 2 14
"llo myname is"
127.0.0.1:6379> keys *
1) "keyname2"
2) "yhkey1"
3) "yhkey9"
4) "yhkey3"
5) "keyname1"
6) "yhyhkey"
7) "mykey"

#Get multiple strings at the same time
127.0.0.1:6379> GET yhkey1 yhkey3
(error) ERR wrong number of arguments for ‘get’ command
127.0.0.1:6379> MGET yhkey1 yhkey3
1) "redis"
2) "redis"
127.0.0.1:6379> 
5.4redis-hash


add:hmset (simultaneous setting of multiple file-value into the hash table), Hget



deletion:Hdel



check:hget, Hgetall,hkey get all the fields in the hash table (file),


  Hmget myhash file1 file2 file3 (returns the value of one or more given fields in a hash table)


Hvals get all the values in the hash table



sentence:hexists judge whether there is



Hlen Get file Count


5.5redis-list


The Redis list is a simple list of strings, sorted by insertion order. You can add an element to the head of the list (to the left) or to the tail (to the right)



Increase: Lpush (header insertion Element), Rpush (trailing insert Element)



Delete: Lpop (removes the first element of the list), Rpop (removes the last element of the list), Lrem KeyName count value (count greater than 0 deletes the value element from the head)



Check: Llen (get list length), Lreng key start Stop (get start to stop Element)



Change: LSet, RSet


5.6redis-set


Increase: Sadd,



Sunionstore myset myset1 Myset2 Command stores the assembly of a given collection in the specified collection MySet



Delete: Spop remove random number from collection



Srem removing elements from a collection by value



Check: Smembers, SCard (get member number),



Sdiff (lists the elements that the first collection owns, the second collection does not),



Sdiffstore (holds the first collection, the elements that are not in the second collection are saved to the third collection),



Sinter (lists the intersection of two collections)



Smembers List all members of a collection



Change:smove myset1 myset2 "Key1" moves key1 from Myset1 to Myset2



Sismember: Determines whether the element is a member of key


5.7redis-zset


A Redis ordered collection is a collection of elements of type string, as well as a collection, and does not allow duplicate members.



Add: Zadd keyname Scoren value



Delete: Zrem keyname nember Remove one or more members from an ordered collection



Zremrangebylex key min Max removes all members of the given dictionary interval in the ordered collection.



Zremrangebyrank key Start Stop removes all members of the given rank range in the ordered collection



zremrangebyscore Key min Max removes all members of a given fractional interval in an ordered collection



Check: Zcard Gets the number of members of the collection



Zcount Key min Max calculates the number of members that specify interval fractions in an ordered set



zrange key start Stop withscores Returns an ordered set of members within a specified range by an index interval


5.8 Business


Redis transactions can execute multiple commands at once



Start transaction: MULTI



Execution transaction: EXEC



Cancel transaction: DISCARD cancels the transaction and discards all commands within the transaction block



Monitoring transactions: Watch monitors one or more keys, and if this (or these) keys are changed by other commands before the transaction is executed, the transaction is interrupted



Suppress monitoring: unwatch suppress watch command for all key monitoring.


5.9 Scripts


The Eval command executes the script using the Lua interpreter.



5.10 Servers



Redis server commands are primarily used to manage redis services.



Statistical parameters: INFO



Reset some statistics in the INFO command: Config resetstat



Number of keys: dbsize



Delete all Key:flushall



Delete Current Database key:flushdb



Save data asynchronously to hard disk: Save


6.Redis Advanced 6.1Redis Data backup and recovery


Backup: Save



Recovery: 1: Move the generated RDB file to the Redis installation directory (execute config get dir) and start the service



You can also create a Redis backup file using the command BGSAVE, which executes in the background.


6.2Redis Security
Set"Itnihao" Auth Itnihaoget requirepass 
6.3Redis Performance Test6.4Redis Client Connection


To view the maximum number of connections:config get maxclients



To set the maximum number of connections: Redis-Server --maxclients 100000


6.5Redis Pipeline Technology


Redis pipeline technology can continue to send requests to the server when the service side is not responding, and eventually read all server-side responses at once.


6.6Redis Partitioning


Partitioning is the process of splitting data into multiple Redis instances, so each instance holds only a subset of the keys.



Key-value Type Store Database--redis


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.