How to Remotely Inspect the Data in My Rediscloud Dbs

How can I remotely inspect the data in my RedisCloud DBs?

Step by step:

1 - Check your Heroku config, in order to find out the REDIS URL.

heroku config

You should see an entrance that look like this:

REDISCLOUD_URL:              redis://rediscloud:foobarfoobarfoobar@a-redis-address:18888

2 - Connect to your remote Redis DB using redis-cli:

redis-cli -h a-redis-address -p 18888 -a foobarfoobarfoobar

You should be able to query your Redis DB now.

How to remotely inspect data with Heroku / RedisCloud / Node.js

redis-cli isn't a Ruby tool, it is a standard part of the Redis package. The easiest way of getting on your Mac is to download and build Redis from https://github.com/antirez/redis. Once you've done that, your laptop will be able to use the compiled binary.

Note that when in a bind and in need of connecting to Redis, you can also use plain telnet.

How to connect to redislabs in Python

I first used

telnet redis.us-east-1-1.ec2.cloud.redislabs.com 18274

to make sure it was not a connectivity issue (many servers have Ping turned off).

On the RedisLabs website, they give you what is called an endpoint that ends with the colon and port number. Apparently, you cannot use that as your host in Python (other tools and products often combine the two), you have to split it up, so for example:

Doesn't work:

host_info = "redis.us-east-1-1.ec2.cloud.redislabs.com:18274"
redisObj = redis.Redis(host=host_info, password='xxx')

Works:

host_info2 = "redis.us-east-1-1.ec2.cloud.redislabs.com"
redisObj = redis.Redis(host=host_info2, port=18274, password='xxx')

I've got another issue to fix on my sample, but I'm not getting connection error any more.

Also see "Basic Connection Troubleshooting" on RedisLabs.

Searching by multiple values within a redis key/value

There are few problems in @orangeoctopus usecae.

redis 127.0.0.1:6379> HMSET id:4532143215432 username davejlong emaildave@davejlong.com
OK
redis 127.0.0.1:6379> HMSET user:davejlong id 4532143215432 email dave@davejlong.com
OK

This will make duplication, think about adding new values and deleting & updating.

So I prefer this

SET user:davejlong 1
HMSET user:1 username davejlong email dave@davejlong.com

1) In case of username

 redis.get('user:davejlong',function(err,id){
console.log('User Id of @davejlong: ' + id);
redis.hgetall('user:'+id,function(err,user){
console.log('User Data: ' + user);
})
})

2) In case of Id

   redis.hgetall('user:1',function(err,user){
console.log('User Data: ' + user);
})

Flushing portions of a Redis cache

I can think of three approaches to achieve that.

Shared Databases - Worst Approach (as in highly recommended not to pursuit)

Redis supports shared databases that are basically separate keyspaces managed by the same server. After connecting to your Redis, you switch between the databases with the SELECT statement and you can use the FLUSHDB command to flush each one individually.

Pro:

  • This is the simplest way to get exactly what you need.

Cons:

  • Shared databases share the same Redis process. Since Redis is (mostly) single-threaded, the practice of using shared databases is not recommended as operations in one database can interfere with other databases running on the same server.
  • It isn't clear whether support for shared databases will be continued in future versions of Redis.

(For more information on Shared vs. Dedicated Redis databases, check out my post at http://redislabs.com/blog/benchmark-shared-vs-dedicated-redis-instances)

One Database, Different Key Prefixes - Slightly Better but still...

You could use a single Redis database and prefix you keys according to the "area" they belong to (e.g. keys that go into the ASP.Net area will be prefixed with 'asp:' etc...). To delete an area, iterate through the keyspace with the SCAN command using the relevant key name pattern and DEL the results it returns.

Pros: can't think of any
Cons:

  • Same as the above + more coding to implement the SCAN/DEL routine.

Dedicated Databases - Recommended Approach

Use a separate Redis instance for each area, plain and simple. Set up your remote machine to run 3 Redis servers, each managing its own keyspace. To flush, connect to the relevant database and do FLUSHDB or FLUSHALL.

Pros:

  • Flush an area with a single command
  • Leverage multiple cores on the remote machine

Con:

  • Could mean a little more administrative effort to set up 3 Redis servers.

Lastly, if you're looking for a way to use Redis without the hassle, I urge you to consider Redis Cloud as an option for a hosted Redis service in the Cloud. We are the only service provider that lets you set up multiple, dedicated Redis databases in the same subscription at no extra cost.



Related Topics



Leave a reply



Submit