Nosql&redis

Source: Internet
Author: User
Tags delete key

I. Learning NoSQL

1. Case and Comment
Import Redis

R = Redis. Redis (host= "192.168.48.136", port=6379, Db=0)
Print (R)
Print (R.keys ())
Print (R.get ("AAA"). Decode ("Utf-8"))

# string manipulation
# Get (Key)
# Set (key, value)
# mget (K1, K2, K3, K4)
# Mset (K1=V1, K2=v2)

# operation of the list
# Add Lpush (name, value) to the left
# Add Rpush (name, value) to the right
# Insert Linsert (name, where, Refvalue, value)
# Left Delete lpop (name)
# Lrange values in list by sharding (name, start, end)
# Modify a value in the list LSet (name, index, value)
# Delete the specified value Lrem (name, value, num) num defaults to 0, delete all, num=2 remove 2 elements from left to right, num=-1 remove two elements from right to left

R.lpush ("Testlist1", 1)
R.lpush ("Testlist1", 2, 3, 4)
Print (R.lrange ("Testlist1", 0,-1))


# set operation
# Add Sadd (name, values)
# get SCard (name)
# delete Spop (name) s.srem (name, value)
# and set Sunion (keys) For example: Suniion ("A", "B", "C")
# intersection Sinter (Key)


# hash Main to master the operation of string and hash
# get the details of key Hgetall (name)
# set a single element Hset (name, key, value)
# Set multiple elements Hmset (name, {"Key": "Value"})
# get a single element Hget (name, key)
# Get multiple elements Hmget (name, keys)
# Get multiple key Hkeys (name)
# Get multiple value hvals (name)
# Determine if key exists hexists (name, key)
# Delete key Hdel (name, keys)
# Get length Hlen (name)
R.hset ("Testhash", "K1", "v1")
Print (R.hget ("Testhash", "K1"))
Print (R.hgetall ("Testhash"))

R.hmset ("testhash111", Dict (k1= "v1", k2= "v2", k3= "V3"))
Print (R.hgetall ("testhash111"))


# Other common operations for all types
# R.keys () View all keys
# r.delete (names) Delete keys
# r.exists (name) to determine if there is
# r.rename (SRC, DST) New old
# R.expire (name, time) set timeout
# R.type (name) to see what type of Redis data the name belongs to
# R.move (name, DB) move the name from the db of the principle to the DB Library
# r.flushall () Delete all keys

Case two.
Import Memcache

MC = Memcache. Client ([' 192.168.48.136:12000 '])
Print (MC)
Mc.set ("AAA", "Hello World")
Print (Mc.get ("AAA"))

# Set (key, value)
# Get (Key)
# Repalce (Key, New_value)
# set = add + replace ()
# Delete (key)
# Get_multi ([K1, K2, K3])
# Delete_multi ([K1, K2, K3])
# Set_multi ({"K1": "V1", "K2": "V2"})
# append (k, appendvalue)
# prepend (k, Prependvalue)
Mc.append ("AAA", "321")
Print (Mc.get ("AAA"))
Mc.prepend ("AAA", "123")
Print (Mc.get ("AAA"))
Print (Mc.stats)




# Mc.add ("Mctestadd", "Nihaoma")
# Print (Mc.get ("Mctestadd"))

Nosql&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.