Examples
-
a. Let’s create the keyspace
b. Let’s create the table:
CREATE TABLE animals:cat keymap(str,binstr)
c. Let’s switch to the table:
USE animals:cat
d. Let’s inspect it:
INSPECT TABLE animals:cat
e. Let’s drop the table:
DROP TABLE animals:cat
f. Let’s drop the keyspace
DROP KEYSPACE animals
Create a keymap table called ‘cache’ in the ‘default’ keyspace that is volatile. Our cache key is an
str
while the value would be some binary data, sobinstr
:CREATE TABLE cache keymap(str,binstr) volatile
Lists
Create a table called ‘notes’ in the default keyspace. We’ll have usernames linked to a collection of notes made by them. Since the names are unicode values, we’ll use the
str
type for the key. For the data type, we’ll use thelist
type, with the inner type asstr
since the notes will also have unicode characters (like emojis, for example). If we needed to store binary data within the lists, we’d simply use thebinstr
data type instead.Now let’s switch to the table
use default:notes
Let’s add some notes made by our theoretical user
joe
. This is how it goes (#
signs were simply added for explanations, simply ignore them):LSET sayan
# now append some notes
LMOD sayan PUSH "Just woke up. Jotting down today's first note!"
LMOD sayan PUSH "Heading to the subway; gotta get to work fast!"
LMOD sayan PUSH "Funny that someone broke my chair! Just called someone to get it fixed!"
LMOD sayan PUSH "Brrr...on my work machine. See you later!"
LMOD sayan PUSH "Done with work, now heading home!"
LMOD sayan PUSH "Woot, I'm home. What a hectic day!"
Let’s read all the notes:
LGET sayan
This would have printed out all the notes if we were using the command-line client, like this:
-
LGET sayan LIMIT 5
This would output:
(1) "Just woke up. Jotting down today's first note!"
(3) "Funny that someone broke my chair! Just called someone to get it fixed!"
(4) "Brrr...on my work machine. See you later!"
Now let’s remove the “broken chair” note because it turns out that I actually had the wrong chair!
LMOD sayan REMOVE 2
Let’s see what we have with
LGET sayan
:(1) "Just woke up. Jotting down today's first note!"
(2) "Heading to the subway; gotta get to work fast!"
(3) "Brrr...on my work machine. See you later!"
(4) "Done with work, now heading home!"
(5) "Woot, I'm home. What a hectic day!"
Wait, I forgot about something! Someone left a mysterious letter on my desk. I discovered it as soon as I entered my workplace. Let’s insert that:
LMOD sayan INSERT 2 "Just discovered a mysterious letter on my desk! How cool!"
Let’s get our entire bunch of notes now:
(1) "Just woke up. Jotting down today's first note!"
(2) "Heading to the subway; gotta get to work fast!"
(3) "Just discovered a mysterious letter on my desk! How cool!"
(4) "Brrr...on my work machine. See you later!"
(6) "Woot, I'm home. What a hectic day!"