Simple additions and deletions of the five data types of Redis

Source: Internet
Author: User
Tags set set redis cli redis server

Have a nice smile

The tortoise was wounded. Let the snail buy medicine. It's been 2 hours. The snail hasn't come back yet. Turtle nasty scold: no fucking come back I'm dead! Then came the voice of the Snail outside the door: You say the mother said I do not go!

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#查询ay_key的值127.0.0.1:6379> get ay_key"ay"#修改ay_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 *1) "new_ay_key"#删除ay_key127.0.0.1:6379> del ay_key(integer) 0#查询是否存在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#生成set集合,添加4个数据127.0.0.1:6379> sadd set_ay_key "ay" "al" "xy" "xl"(integer) 4#查询set里面所有值127.0.0.1:6379> smembers set_ay_key1) "xy"2) "al"3) "ay"4) "xl"#删除value为"xl" , 返回 1  如果没有返回 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"#添加value为"xl"  添加不进去,但也不报错,set是不允许重复的127.0.0.1:6379> sadd set_ay_key "xl"(integer) 0#不多解释127.0.0.1:6379> sadd set_ay_key "xl"(integer) 0#不多解释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#查询key为list_ay_key的集合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) 5#往list头部添加元素127.0.0.1:6379> lpush list_ay_key "first"(integer) 6#查询list集合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 list_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) "together"#删除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 collection 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 _two "22222" (integer) # Collection add 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 four: SortedSet collection of additions and deletions

SortedSet is an ordered set set

#sorted set添加值ay 排序值为 1127.0.0.1:6379> zadd zset_ay_key 1 "ay"(integer) 1127.0.0.1:6379> zadd zset_ay_key 2 "al"(integer) 1127.0.0.1:6379> zadd zset_ay_key 3 "xy"(integer) 1127.0.0.1:6379> zadd zset_ay_key 4 "xl"(integer) 1#查询所有的值127.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"(integer) 0127.0.0.1:6379> zrange zset_ay_key 0 -11) "ay"2) "al"3) "xy"4) "xl"

Don't write, good tired, all the same, look at the following article .....

refer to the master article

Http://www.runoob.com/redis/redis-sorted-sets.html

Reading Comprehension

From "Changjiang Seventh"
-Star Master's instruction on his son (repeated 3 times in the film)-we are poor, but we can not lie, we cannot beat people, not our things, we can not take, to study hard, grow up to be a useful society.

other

If there is a little bit of happiness for you, let happiness continue to pass, welcome reprint, Praise, top, welcome to leave valuable comments, thank you for your support!

Simple additions and deletions of the five data types of 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.