Five types of Redis data type simple operation detailed

Source: Internet
Author: User
Tags redis cli redis server
Redis is an open source API that is written in ANSI C, supports the web, can be persisted in memory, key-value databases, and provides multiple languages. This article mainly introduced the Redis in five kinds of data types simple operation of the relevant data, the need for friends can refer to, hope to help everyone.

Simple operation of five data types in Redis

Ask questions

Redis Five types of data type of simple additions and deletions to change the command???

Solve the problem

Suppose you have a Redis server installed;
Suppose you have opened the Redis CLI command-line tool;
Let's say you know something about Redis;

Redis simple additions and deletions to find examples

Example one: string additions and deletions

#增加一个key为ay_key的值127 .0.0.1:6379> set Ay_key "ay" ok# query Ay_key value 127.0.0.1:6379> get Ay_key "ay" #修改ay_ The value of key 127.0.0.1:6379> set Ay_key "New_ay" ok127.0.0.1:6379> get Ay_key "New_ay" #修改ay_key名称127 .0.0.1:6379> Rename Ay_key new_ay_keyok127.0.0.1:6379> keys *) "New_ay_key" #删除ay_key127 .0.0.1:6379> del ay_key (integer) 0# Whether the query exists Ay_key 0127.0.0.1:6379> exists ay_key (integer) 0

Example two: Adding and deleting of Set set

#删除当前选择数据库中的所有key127 .0.0.1:6379> flushdbok# generates a set set, adding 4 data 127.0.0.1:6379> sadd set_ay_key "ay" "Al" "XY" "XL" ( Integer) 4# query set inside all values 127.0.0.1:6379> smembers set_ay_key1) "XY" 2) "Al" 3) "Ay" 4) "XL" #删除value为 "XL", return 1 if not returned 0127.0. 0.1:6379> Srem Set_ay_key "XL" (integer) 1127.0.0.1:6379> smembers set_ay_key1) "XY" 2) "Al" 3) "Ay" #添加value为 "XL" 127.0.0.1:6379> sadd Set_ay_key "XL" (integer) 1127.0.0.1:6379> smembers set_ay_key1) "XY" 2) "Al" 3) "Ay" 4) "XL" # Add value for "XL" add does not go in, but also do not error, set is not allowed to repeat the 127.0.0.1:6379> sadd Set_ay_key "XL" (integer) 0# not much explanation 127.0.0.1:6379> Sadd set _ay_key "XL" (integer) 0# not much explanation 127.0.0.1:6379> Sadd Set_ay_key "XL" (integer) 0

Example three: List collection of additions and deletions to search

#添加key为list_ay_key的list集合127 .0.0.1:6379> lpush list_ay_key "ay" "Al" "XY" "XL" (integer) 4# query key is List_ay_ Key collection 127.0.0.1:6379> Lrange list_ay_key 0-11) "XL" 2) "XY" 3) "Al" 4) "Ay" #往list尾部添加元素127 .0.0.1:6379> rpush List_ay _key "Together" (integer) AA adds elements to list header 127.0.0.1:6379> Lpush list_ay_key "First" (integer) 6# query list collection 127.0.0.1:6379 > Lrange list_ay_key 0-11) "First" 2) "XL" 3) "XY" 4) "Al" 5) "ay" 6) "Together" #更新index为0的值  127.0.0.1:6379> LSet li St_ay_key 0 "Update_first" ok127.0.0.1:6379> lrange list_ay_key 0-11) "Update_first" 2) "XL" 3) "XY" 4) "Al" 5) "ay" 6) "Tog Ether "#删除index为1上的值127 .0.0.1:6379> lrem list_ay_key 1" update_first "(integer) 1127.0.0.1:6379> lrange List_ay_ Key 0-11) "XL" 2) "XY" 3) "Al" 4) "Ay" 5) "Together"

Example four: Hash collection (Java-like) additions and deletions

127.0.0.1:6379> flushdbok# generates a hash set and adds a key of Uuid_one value to "12345" 127.0.0.1:6379> hset hash_ay_key "Uuid_one" " 12345 "(integer) 1127.0.0.1:6379> hlen hash_ay_key (integer) # returns the collection all key127.0.0.1:6379> Hkeys hash_ay_key1)" Uuid_one "#返回集合所有value127 .0.0.1:6379> hvals hash_ay_key1)" 12345 "#集合添加值127 .0.0.1:6379> hset Hash_ay_key" uuid_ The "22222" (integer) # collection adds a value 127.0.0.1:6379> hset hash_ay_key "Uuid_three" "33333" (integer) # get key to Uuid_ The value of one 127.0.0.1:6379> hget hash_ay_key uuid_one "12345" #删除key为uuid_three的值127 .0.0.1:6379> hdel hash_ay_key uuid_ Three (integer) 1127.0.0.1:6379> hkeys hash_ay_key1) "Uuid_one" 2) "Uuid_two" #获得所有, including key and value127.0.0.1:6379> Hgetall hash_ay_key1) "Uuid_one" 2) "12345" 3) "Uuid_two" 4) "22222" #更新key为uuid_one的值127 .0.0.1:6379> hset Hash_ay_key Uuid_one "11111" (integer) 0127.0.0.1:6379> hset hash_ay_key "Uuid_one" "11111" (integer) 0127.0.0.1:6379> hgetall Hash_ay_key1) "Uuid_one" 2) "11111" 3) "Uuid_two" 4) "22222"

Example five: SortedSet collection of additions and deletions

SortedSet is an ordered set set

#sorted Set add value ay sort value 1127.0.0.1:6379> zadd zset_ay_key 1 "ay" (integer) 1127.0.0.1:6379> zadd zset_ay_key 2 "Al" (int Eger) 1127.0.0.1:6379> zadd zset_ay_key 3 "xy" (integer) 1127.0.0.1:6379> zadd zset_ay_key 4 "XL" (integer) # query all values 1 27.0.0.1:6379> zrange zset_ay_key 0-11) "Ay" 2) "Al" 3) "XY" 4) "XL" #删除所有的值127 .0.0.1:6379> zrem Zet_ay_key "XL" (Integ ER) 0127.0.0.1:6379> zrange zset_ay_key 0-11) "Ay" 2) "Al" 3) "XY" 4) "XL"

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.