Currently i have plan a process of using a script to add key values into redis using rpush.
I am currently using bin/sh to launch redis.
But what is the syntax to rpush my keyvalue into redis server.
#!/bin/sh
redis-cli -h 172.16.114.54
rpush stlfile "fad.stl" // how to rpush in with the correct syntax?
What kind of language is more suitable for redis so maybe i could change now to ease my future processes
Seems like using python would be easier to code Redis
from this post i found here i can easily install python.
ImportError: No module named redis
i managed to create a python script with this
import redis
r = redis.StrictRedis(host='172.16.114.54', port=6379, db=0)
r.lpush ('stlfile', 'variable.stl')
r.lrange ('stlfile', 0, -1)
when checked with another client i managed to see variable.stl went in :D
Related
I am trying to connect to my Redis instance from a groovy script (ExecuteGroovyScript) and execute arbitrary commands such as LPUSH. I currently have RedisConnectionPoolService enabled and working fine for caching processors.
Is there any way to achieve this? Any examples are appreciated.
EDIT:
I got to the point where I can call a command but for some reason it fails, here is the code and error
service = context.getControllerServiceLookup().getControllerService("2b841623-35ed-1e1a-0a77-46087267939d")
service.getConnection().withCloseable { redis ->
redis.listCommands().lPush("key".getBytes(), "1".getBytes())
}
If you have a RedisConnectionPoolService called service and call service.getConnection(), you will have a Spring Redis RedisConnection instance, so you can check their API for the kinds of calls you can make.
For LPUSH specifically you can call service.getConnection().listCommands().lpush()
I have setup Spark SQL on Jypterhub using Apache Toree SQL kernel. I wrote a Python function to update Spark configuration options in the kernel.json file for my team to change configuration based on their queries and cluster configuration. But I have to shutdown the running notebook and re-open or restart the kernel after running Python function. In this way, I'm forcing the Toree kernel to read the JSON file to pick up the new configuration.
I thought of implementing this shutdown and restart of kernel in a programmatic way. I got to know about the Jupyterhub REST API documentation and am able implement it by invoking related API's. But the problem is, the single user server API port is set randomly by the Spawner object of Jupyterhub and it keeps changing every time I spin up a cluster. I want this to be fixed before launching the Jupyterhub service.
Here is a solution I tried based on Jupyterhub docs:
sudo echo "c.Spawner.port = 35289
c.Spawner.ip = '127.0.0.1'" >> /etc/jupyterhub/jupyterhub_config.py
But this did not work as the port was again set by the Spawner randomly. I think there is a way to fix this. Any help on this would be greatly appreciated. Thanks
On ubuntu 16.04. Interacting with a local redis instance via redis-cli. Working with a node hubot script which uses redis as its primary data store.
when I type keys * I get a single key hubot:storage
so I FLUSHALL and get an ok response. But if the Hubot is running or else as soon as it turns on, it restores the value of that key immediately so I can never delete it.
I'v used the info command to try to see if it is persisting on some other redis instance and I've cleared all backup files from /var/redis. Basically I can't figure out where this data is being stored to keep getting restored from.
Any advice regarding how I could clear this out or where Hubot may be caching this?
It seems to be related to this code: https://github.com/hubotio/hubot-redis-brain/blob/master/src/redis-brain.js specifically the chunk at line 49 is what gets called before each restore.
Steps
Stop hubot
Flush redis (important that this is done while hubot is NOT running)
Start hubot
The reasoning is that hubot has an in-memory representation of the brain and will write it out to redis at intervals. Perhaps a nicer solution to this which would help during script development would be a command that can empty the brain and save that, but I can't see an obvious API for that in either robot.brain or hubot-redis-brain
https://github.com/antirez/redis/issues/3689
On a RHEL(RedHat) machine installed Redis 3.0.7 as a deamon: Let's call this "A" .
On a Windows Server 2012 machine installed Redis 3.2.1 as a service: Let's call this "B".
I want to migrate the key of "IdentityRepo" from A to B. In order to achive that I tried to execute the following command on Redis A.
migrate <IP of B> 6379 "IdentityRepo" 3 1000 COPY REPLACE
The following error occured:
(error) ERR Target instance replied with error: ERR DUMP payload version or checksum are wrong
What can be the problem?
The encoding version was changed between these v3.0 to v3.2 due to the addition of quick lists, so MIGRATE as well as DUMP/RESTORE will not work in that scenario.
To work around it, you'll need to read the value from the old database and then write it to the new one using any Redis client.
I am using Spring Jedis Client to use Redis in my application. I want to rename the commands so that no one else can fire the same just in case they are able to connect to my server.
Can anyone give an example of how to use rename command from Jedis and then how to fire subsequent commands using the the modified one ?
You can't rename a Redis command yet w/o changing the config file issue #640.
Even if you add the rename-command config file directive and restart your Redis, Jedis doesn't seem to allow sending arbitrary commands easily or to provide a trivial (i.e. no code changes) way to rename them.
What you could do, however, if you're really insistent on renaming a command and then calling it from Jedis is EVAL it. This will probably go in my pantheon of ugly hacks (:)) but after adding rename-command get foo to my /etc/redis/redis.conf and doing service redis-server restart look what I can do:
$ redis-cli
redis 127.0.0.1:6379> set bar baz
OK
redis 127.0.0.1:6379> get bar
(error) ERR unknown command 'get'
redis 127.0.0.1:6379> foo bar
"baz"
redis 127.0.0.1:6379> eval "return(redis.call('get', KEYS[1]))" 1 bar
(error) ERR Error running script (call to f_db0e060e4f58231d51f21685b20ff847de8ab9e1): Unknown Redis command called from Lua script
redis 127.0.0.1:6379> eval "return(redis.call('foo', KEYS[1]))" 1 bar
"baz"
redis 127.0.0.1:6379>
Of course, if you take this route your code can get pretty messy in no time at all so be careful where you tread... Good luck!
If a malicious user connects directly to Redis, then one can access all opcodes.
There is no feature in the Redis library to rename commands. Even if you expose access to a custom API that renames commands, you cannot change the inner opcodes of Redis itself.
Edit:
You're right, it is possible to rename commands by changing the config file indeed!
After you set the new command names, you have to recompile Jedis.
First rename the enum on src/main/java/redis/clients/jedis/Protocol.java, line 203.
Now find the corresponding enum usage on src/main/java/redis/clients/jedis/BinaryClient.java and change it also.
It may be sufficient: everywhere you still keep the old command java interfaces (e.g. zadd etc.), and inside Jedis it will talk to Redis calling the renamed command.
Is that your intention ?