Redis Web Server

Source: Internet
Author: User
Tags benchmark key string keep alive redis server

Redis is a key-value storage system. Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), Zset (sorted set--ordered collection) and HASHS (hash type). These data types support Push/pop, Add/remove, and intersection sets and differences, and richer operations, And these operations are atomic. Based on this, Redis supports sorting in a variety of different ways. As with memcached, data is cached in memory for efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modified operation to the appended record file, and on this basis implements the MAS Ter-slave (Master-slave) synchronization.

Advantages of Redis:

Very high performance –redis can support more than 100k+ per second read and write frequency.
Rich data types –redis support binary case Strings, Lists, hashes, sets and Ordered sets data type operations.
All atomic –redis operations are atomic, and Redis supports atomic execution of several operations.
Rich features –redis also supports publish/subscribe, notifications, key expiration, and more.

Here's the official Bench-mark data:
The test completed 50 concurrent executions of 100,000 requests.
The set and get value is a 256-byte string.
Linux box is running Linux 2.6, which is X3320 Xeon 2.5 GHz.
Text execution uses the loopback interface (127.0.0.1).
Result: The write speed is 110,000 times/s, the reading speed is 81,000 times/s.

Redis Common commands:

In the case of DB, Redis scores have been amazing, and not to mention the Memcachedb and Tokyocabinet, the original memcached, the speed seems to reach only this level. Redis is simply using memory storage, and the key to persistence is these three instructions: SAVE BGSAVE lastsave.

When the Save command is received, Redis dumps the data into a file. What is worth saying is its exclusive function: storing lists and collections, which is a more competitive place than MC.
does not introduce the MC inside already has the east, only lists the special:
Type key-is used to get the types of a key
The keys pattern-matches all of the key modes, such as keys, to list all keys, of course, the complexity O (n)
Randomkey-Returns a random key
RENAME Oldkeynewkey-key can also be renamed
List operation, Essence
Rpush key string-adds a value to the header of a key list
Lpush key string-adds a value to the end of a key list
Llen key-List Length
Lrange Key Start end-Returns the value of a range in the list, which is equivalent to a paging query inside MySQL
LTRIM key start end-keep only a range of values in the list
LINDEX key index-Gets the value of a specific index number in the list, be aware of the O (n) complexity
LSET Key index value-set a value for a position in the list
Lpop Key
Rpop key-, like the lpop above, is the sort of header-and-tail instruction that resembles a stack or queue, and can be used as a message queue.
Collection operations
Sadd Key member-add element
Srem Key member-Delete element
SCard key-Return Collection size
Sismember key member-Determines whether a value is in the collection
SINTER key1 Key2 ... keyn-gets the intersection element of multiple collections
Smembers key-Lists all elements of a collection
There are also multiple DB commands that can be replaced with DB, data can be isolated and stored in DB 0 by default

Redis Installation Method:

Can be installed under Windows

After the Redis installation file is unpacked, there are several files. See

Redis-server.exe: Service Program
Redis-check-dump.exe: Local Database check
Redis-check-aof.exe: Update log check
Redis-benchmark.exe: Performance test to simulate the simultaneous sending of M-Sets/gets queries by n clients (similar to the Apache AB tool).

After extracting the Redis installation files to the E:\ root directory, you also need to add a Redis profile redis.conf to the Redis root directory, which is included in the file specific content, but here I still post the contents of the configuration file:

# Redis Configuration File Example

# By default, Redis does not run as a daemon. Use the ' yes ' if you need it.
# Note that Redis would write a PID file in/var/run/redis.pid when daemonized.
Daemonize No

# when run as a daemon, the Redis write a PID file in/var/run/redis.pid by default.
# can specify a custom PID file location here.
Pidfile/var/run/redis.pid

# Accept connections on the specified port, default is 6379
Port 6379

# If you want your can bind a single interface if the BIND option isn't
# specified all the interfaces would listen for connections.
#
# bind 127.0.0.1

# Close The connection after a client are idle for N seconds (0 to disable)
Timeout 300

# Set Server verbosity to ' debug '
# It can be one of:
# Debug (a lot of information, useful for development/testing)
# notice (moderately verbose, what are want in production probably)
# warning (only very important/critical messages is logged)
LogLevel Debug

# Specify the log file name. Also ' stdout ' can is used to force
# The demon to log in the standard output. Note If you use the standard
# Output for logging but daemonize, logs'll be sent To/dev/null
LogFile stdout

# Set the number of databases. The default database is DB 0, you can select
# A different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and ' databases '-1
Databases 16

################################ snapshotting #################################
#
# Save the DB on disk:
#
# Save <seconds> <changes>
#
# would save the DB if both the given number of seconds and the given
# Number of write operations against the DB occurred.
#
# in the example below the behaviour would be is to save:
# After the SEC (min) If at least 1 key changed
# After the SEC (5 min) If at least ten keys changed
# after the SEC if at least 10000 keys changed
Save 900 1
Save 300 10
Save 60 10000

# Compress String objects using LZF when dump. RDB databases?
# for default this ' s set to ' yes ' as it's almost always a win.
# If you want to save some CPU on the saving child set it to ' no ' but
# The DataSet would likely is bigger if you have compressible values or keys.
Rdbcompression Yes

# The filename where to dump the DB
Dbfilename Dump.rdb

# for Default Save/load DB in/from the working directory
# Note that you must specify a directory is not a file name.
Dir./

################################# REPLICATION #################################

# Master-slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration was local to the slave
# So for example it's possible to configure the slave to save the DB with a
# different interval, or to listen to another ports, and so on.
#
# slaveof <masterip> <masterport>

# If The master is password protected (using the "Requirepass" configuration
# directive below) It's possible to tell the slave to authenticate before
# Starting the replication synchronization process, otherwise the master would
# refuse the slave request.
#
# Masterauth <master-password>

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing
# commands. This might is useful in environments in which don't trust
# Others with access to the host running Redis-server.
#
# This should stay commented out for backward compatibility and because most
# People do not need auth (e.g. they run their own servers).
#
# Requirepass Foobared

################################### LIMITS ####################################

# Set The max number of connected clients at the same time. By default there
# is no limit, and it's up to the number of file descriptors the Redis process
# is able to open. The special value ' 0 ' means no limts.
# Once The limit is reached Redis would close all the new connections sending
# an error ' max number of clients reached '.
#
# maxclients 128

# Don ' t use more memory than the specified amount of bytes.
# When the memory limit is reached Redis would try to remove keys with an
# EXPIRE set. It'll try to start freeing keys this is going to expire
# in little time and preserve keys with a longer time to live.
# Redis would also try to remove objects from free lists if possible.
#
# If All this fails, Redis'll start to reply with errors to commands
# that would use more memory, like SET, Lpush, and so on, and would continue
# to reply to more read-only commands like GET.
#
# warning:maxmemory can is a good idea mainly if you want to use Redis as a
# ' state ' server or cache, not as a real DB. When Redis is used as a real
# Database The memory usage would grow over the weeks, it'll be obvious if
# It is going-too much memory in the long run, and you'll have the time
# to upgrade. With MaxMemory after the limit was reached you ' ll start to get
# Errors for write operations, and this may even leads to DB inconsistency.
#
# maxmemory <bytes>

############################## APPEND only MODE ###############################

# By default Redis asynchronously dumps the datasets on disk. If You can live
# with the idea, the latest records would be lost if something like a crash
# happens this is the preferred-to-run Redis. If instead a lot
# about your data and don ' t want to the a single record can get lost you should
# enable the Append only mode:when this mode is enabled Redis would append
# every write operation received in the file Appendonly.log. This file would
# be-Read on startup ' order to rebuild the full dataset in memory.
#
# Note So you can have both the async dumps and the append only file if you
# like (Comment the "Save" statements above to disable the dumps).
# still if append only mode is enabled Redis would load the data from the
# log file at startup ignoring the Dump.rdb file.
#
# The name of the append only file is "Appendonly.log"
#
# Important:check The bgrewriteaof to Check what to rewrite the append
# log file in background when it gets too big.

AppendOnly No

# the Fsync () call tells the Operating System to actually write data on disk
# instead to wait for more data in the output buffer. Some OS would really flush
# data on disk, some other OS would just try to do it ASAP.
#
# Redis supports three different modes:
#
# No:don ' t Fsync, just let the OS flush the data when it wants. Faster.
# Always:fsync after every write to the append only log. Slow, safest.
# Everysec:fsync only if one second passed since the last fsync. Compromise.
#
# The default is "always" that ' s the safer of the options. It ' s up to you
# Understand if you can relax this to ' everysec ' that'll fsync every second
# or to ' no ' that would let the operating system flush the output buffer when
# It want, for better performances (and if you can live with the idea of
# Some data loss consider the default persistence mode that ' s snapshotting).

Appendfsync always
# Appendfsync Everysec
# Appendfsync No

############################### Advanced CONFIG ###############################

# Glue Small output buffers together in order to send small replies in a
# single TCP packet. Uses a bit more CPUs but most of the times it's a win
# in terms of number of queries per second. Use ' yes ' if unsure.
Glueoutputbuf Yes

# Use object sharing. Can save a lot of memory if you have many common
# string in your datasets, but performs lookups against the shared objects
# Pool So it uses more CPUs and can be a bit slower. Usually it ' s a good
# idea.
#
# When object sharing are enabled (Shareobjects Yes) you can use
# Shareobjectspoolsize to control the size of the pool used in order to try
# object Sharing. A bigger pool size would leads to better sharing capabilities.
# In general your want this value is at least the double of the
# Very common strings you have an in your dataset.
#
# Warning:object sharing is experimental, and don ' t enable this feature
# in production before of Redis 1.0-stable. Still try this feature in
# Your development environment so we can test it better.
# Shareobjects No
# shareobjectspoolsize 1024

Extract the Redis_conf.rar from the attachment and place it in the root of the Redis. Here, the Redis installation is complete. Start using the Redis database below.

To start Redis:
Input command: Redis-server.exe redis.conf
After startup as shown:

Start the cmd window to remain open, and the Redis service shuts down when it is closed.
When the service is opened, another window is opened, and the client is set up:
Input command: redis-cli.exe-h 202.117.16.133-p 6379
Enter the following as shown:

Then you can start playing:
Set a key and get the value returned:

$./REDIS-CLI Set MyKey somevalue
Ok
$./REDIS-CLI Get MyKey
Somevalue

How to add a value to list:

$./redis-cli Lpush mylist firstvalue
Ok
$./redis-cli Lpush mylist SecondValue
Ok
$./redis-cli Lpush mylist Thirdvalue
Ok
$./redis-cli Lrange mylist 0-1
. Thirdvalue
. SecondValue
. Firstvalue
$./REDIS-CLI Rpop MyList
Firstvalue
$./redis-cli Lrange mylist 0-1
. Thirdvalue
. SecondValue

Redis-benchmark.exe: Performance test to simulate the simultaneous sending of M-Sets/gets queries by n clients (similar to the Apache AB tool).

./redis-benchmark-n 100000–c 50
====== SET ======
100007 requests completed in 0.88 seconds (Translator note: 100004 queries completed in 1.14 seconds)
Parallel clients (Translator Note: 50 concurrent clients)
3 bytes Payload (Translator Note: 3 byte payload)
Keep Alive:1 (translator Note: Keep 1 connections)
58.50% <= 0 milliseconds (Translator Note: MS)
99.17% <= 1 milliseconds
99.58% <= 2 milliseconds
99.85% <= 3 milliseconds
99.90% <= 6 milliseconds
100.00% <= 9 milliseconds
114293.71 Requests per second (translator Note: 114293.71 queries per second)

Test concurrent client limit to 60 under windows

Redis Web Server

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.