Skip to content

Instantly share code, notes, and snippets.

@ramingar
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save ramingar/e7e6dc6f1630679badc5 to your computer and use it in GitHub Desktop.

Select an option

Save ramingar/e7e6dc6f1630679badc5 to your computer and use it in GitHub Desktop.
Redis data types (string) #redis #comandos #string
> set mykey somevalue
OK
> get mykey
"somevalue"

Multiple set o get (MSET and MGET commands) (for reduced latency):

> mset a 10 b 20 c 30
OK
> mget a b c
1) "10"
2) "20"
3) "30"

I may ask SET to fail if the key already exists, or the opposite, that it only succeed if the key already exists:

> set mykey newval nx
(nil)
> set mykey newval xx
OK

Increment command (también existen INCRBY, DECR and DECRBY):

> set counter 100
OK
> incr counter
(integer) 101
> incr counter
(integer) 102
> incrby counter 50
(integer) 152

Exists (existe una clave?), del (borrar la clave):

> set mykey hello
OK
> exists mykey
(integer) 1
> del mykey
(integer) 1
> exists mykey
(integer) 0

type (para saber el tipo de la clave):

> set mykey x
OK
> type mykey
string
> del mykey
(integer) 1
> type mykey
none

expire (insertar una clave que se autodestruirá en x segundos o milisegundos):

> set key some-value
OK
> expire key 5
(integer) 1
> get key (immediately)
"some-value"
> get key (after some time)
(nil)

Usar expire con otros comandos:

> set key 100 ex 10
OK
> ttl key
(integer) 9

IMPORTANTE!! para guardar los cambios en redis puedes usar estos dos comandos:

$ redis-cli save
$ redis-cli shutdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment