golang - redis basic introduction

redis (remote-dictionary-system) that is remote dictionary server, the database is NoSQL:

  • Suitable for caching and persistence;
  • Free open-source, high-performance distributed-memory database;

redis to install and use:

  • Download Redis-x64-3.2.100.zip, then you can extract;
  • Double-click to start the redis redis-server.exe server;

redis five data types:

  • String (String), hash (Hash), list (List), the set (Set), ordered collection (zset);

After redis installed, the default database there are 16 initial default library using a No. 0, No. 0-15, double-redis-cli.exe Open Client:

  • Key-val tian_jia (set)
    set the customary Hello key1
  • Get the current database of all Keys
    Keys *
  • Obtaining a value corresponding key
    get key1
  • Switch databases
    select 1
  • To view the current key-val number of databases
    dbsize
  • Clear the current database kay-val and clear all database-Val Key
    flushdb
    flushall

String:

It is redis basic type, a key corresponding to a value, e.g. str1 = "hello";

binary string type is safe, in addition to ordinary strings, pictures and other data may be stored;

The maximum value is redis string 512M;

Deletions search string change:

  • Increase: set sddress beijing;
  • Find: get address;
  • Delete: del address;
  • Modify: set address nanjing;
  • Set the timeout, the character automatically destroyed after 10s: setex mss01 10 hello, you;
  • A plurality of one-time key-val: mset name gong age 20;
  • Obtaining a plurality of one-time key-val: mget name age;

Hash:

Is a collection of key-value pair, the type of field is a string value and a mapping table, hash is particularly suited for storing objects;

Hash additions and deletions to change search:

  • Add a hash: hset user1 name gong; hset user1 age 20;
  • Obtain a hash: hget user1 name; hget user1 age;
  • Get all the information: hgetall user;
  • To delete a value: hdel user1 age;
  • Adding a plurality of hash values: hmset user2 name bob age 22;
  • Get the value: hmget user2 name age;
  • Statistics Hash a number of elements: hlen user2;
  • Determine whether there is a field: hexists user2 name;

List:

List is a simple list of strings, sort and insertion order can be inserted in the list of elements and the first end of the list;

The nature of the list is a linked list, a list of the elements are ordered, it may be repeated;

The list of additions and deletions to change search:

  • 增加: lpush name bob tom jack; rpush address beijing wuhan shanghai;
  • Find: lrange name 0 -1;
  • Pop: lpop name; rpop name;
  • Delete: del name;
  • Index-index data acquisition: lindex name 1;
  • List Length: llen name;

set:

Set unordered collection of type string, the bottom is the HashTable;

Set also hold a lot of string elements, unordered string element, and the different elements of the duplicate values;

A collection of additions and deletions to change search:

  • Increase: sadd name gong li tan;
  • All inquiries: smembers name;
  • The existence of a single query: sismember name gong;
  • Delete: srem name gong;

Guess you like

Origin www.cnblogs.com/xiximayou/p/11978751.html