Redis, a 2 minutes introduction

8
Redis:Getting started (5 min guide) A noSQL database quick and fast and almost Italian :)

description

Redis a 5 minutes guide

Transcript of Redis, a 2 minutes introduction

Page 1: Redis, a 2 minutes introduction

Redis:Getting started (5 min guide)A noSQL database quick and fast and almost Italian :)

Page 3: Redis, a 2 minutes introduction

Installing Linux$ wget http://download.redis.io/releases/redis-2.6.16.tar.gz

$ tar xzf redis-2.6.16.tar.gz

$ cd redis-2.6.16

$ make

Mac Users:$ port install redis$ brew install redis

Windows:ops :(

Page 4: Redis, a 2 minutes introduction

Getting started 1Start the server$ redis-server

_._

_.-``__ ''-._ _.-`` `. `_. ''-._ Redis 2.6.16 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 7350 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'

[7350] 10 Sep 13:03:33.329 # Server started, Redis version 2.6.16[7350] 10 Sep 13:03:33.329 * The server is now ready to accept connections on port 6379

Page 5: Redis, a 2 minutes introduction

Getting started 2Start the server$ redis-client _._

redis 127.0.0.1:6379> get foo"mirko2"redis 127.0.0.1:6379> set counter 100 OKredis 127.0.0.1:6379> incr counter(integer) 101redis 127.0.0.1:6379> RPUSH mylist "Mirko"(integer) 1redis 127.0.0.1:6379> RPUSH mylist "Mario"(integer) 2redis 127.0.0.1:6379> RPUSH mylist "Fabio"(integer) 3redis 127.0.0.1:6379> lrange mylist 0 2 1) "Mirko"2) "Mario"3) "Fabio"

Page 6: Redis, a 2 minutes introduction

Try reditInteractive console with the commands availablehttp://try.redis.io/

Page 7: Redis, a 2 minutes introduction

Even more...Creating a simple hashmap

HashesRedis Hashes are maps between string fields and string values, so they are the perfect data type to represent objects (eg: A User with a

number of fields like name, surname, age, and so forth):

redis 127.0.0.1:6379> HMSET user:1 username antirez password Mirko age 33

OK

redis 127.0.0.1:6379> HGETALL user:1

1) "username"

2) "antirez"

3) "password"

4) "Mirko"

5) "age"

6) "33"

Want to check is a user exists? (Login)

HMGET user:1000 password password

Page 8: Redis, a 2 minutes introduction

Ok, perfect. But what in Java?Very nice and easy project is

https://github.com/xetorthio/jedis

<dependency> <groupId>redis.clients</groupId>

<artifactId>jedis</artifactId>

<version>2.0.0</version>

<type>jar</type>

<scope>compile</scope>

</dependency>

Jedis jedis = new Jedis("localhost");jedis.set("foo", "bar");

String value = jedis.get("foo");