redisの学无止境

  一花一世界,一叶一菩提;你眼中的我眼中的世界,并非我眼中的你眼中的世界。每个人能从外界得到的信息都是一样的,但是能领悟多少,就见仁见智了。

Introduction to Redis

  Redis is completely open source free, to comply with BSD protocol, and is a high-performance key-value database.

There are 3 characteristics of Redis:

1.Redis support data persistence, you can save the data in memery of the disk, restart it can be reloaded simultaneously.
2.Redis not only supports key-value types of the data, but also provide storage for data structures such as list, set, zset, hash.
3.Redis supports data backup, that is, master-slave mode data backup.

Advantages

  • High performance, writing speed 11000 IO/s, reading speed 81000 IO/s.
  • Rich data types - Redis supports String, Lists, Sets, Hashes and Order Sets for binary cases.
  • Atoms - All Redis operations are atomic, meaning either successful execution or failure is not performed at all. A single opertation is atomic. Multiple oerations also support transactions, atomicity wrapped by MULTI and EXEC instructions.
  • Rich Features - Redis alse supports features such as publish / subscribe, notifications, key expiration, and more.

difference

  • Redis has more complex data structures, meanwhile its atomic operations on them, an evolutionary path that is different from other databases. Redis data types are based on the basic data structure while transparent to programmers, without extra abstraction.
  • Running Redis can be persisted in memory on disk, you have to think about the space of the disk when you use Redis to I/O data with high-speed and different data types, because the amount of data can not be larger than the amount of hardware memory. Another benifit of having an in-memory database is that it is much easier to work in memory than same complex data structure on disk. so that Redis can do a lot of things with high internal complexity. At the same time, they are compact an appendable in terms of disk format cause of they do not require random access.

Install Redis

Windows:

Source: https://github.com/MSOpenTech/redis/releases
1.Download zip whatever you need, and unzip the X64/X86 zip to disk(C:) or wherever you want, and rename the filename with ‘redis’.
2.Open a command window, using command ‘cd’ to change the catalogue in “C:\redis\” and run command “redis-server.exe redis.windows.conf”, then you can enter redis interface.

1
2
3
>>>$ cd C:\redis\

>>>$ redis-server.exe redis.windows.conf

3.Open a new cmd window(do not close the old one), execute next command:

1
2
3
4
5
>>>$ redis-cli.exe -h 127.0.0.1 -p 6379

>>>$ set myKey abc

>>>$ get myKey

Linux:

Source: http://redis.io/download
install redis:

1
2
3
4
5
6
7
$ wget http://download.redis.io/releases/redis-xxx.tar.gz      # xxx=version

$ tar xzf redis-xxx.tar.gz

$ cd redis-xxx

$ make

After ‘make’ redis-xxx, then we need to start up services ‘redis-server’ and ‘redis-cli’ that in file(‘src’).
Start up ‘redis-server’

1
2
$ cd src
$ ./redis-server

Start up ‘redis-cli’

1
2
$ cd src
$ ./redis-cli

File “redis.conf” is a default allocation. we can config it when we need it. After start up Server and Client, now shall we test the redis. For example:

1
2
3
4
5
6
$ cd src
$ ./redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

Ubuntu:

We can install redis in Ubuntu system like these:

1
2
$ sudo apt-get update
$ sudo apt-get install redis-server

start up redis

1
$ redis-server

check if it is really started

1
$ redis-cli

the above commannd opens the following terminal:

1
redis 127.0.0.1:6379>

now we can ping sth

Mac

1
2
3
4
5
6
1.Downlaod official version (http://redis.io )
2.sudo mv /usr/local/
3.sudo tar -zxf redis-xxx.tar
4.Enter the catalogue and untar the file "redis-xxx.tar"
5.sudo make test
6.sudo make install

Redis commands

We input the command to redis-cli(Client)

Basic syntax(Client)

1
$ redis-cli

Example

1
2
3
4
5
$ redis-cli
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> ping
...
ping

Basic syntax(Server)

login to Server

$ redis-cli -h host -p port -a password

Reference

http://www.runoob.com/redis/
http://redis.io/commands

sign bman

-------------本文结束感谢浏览-------------